tmux-ide 2.9.20 → 2.9.21

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.
Files changed (89) hide show
  1. package/bin/cli.js +14684 -3865
  2. package/package.json +3 -2
  3. package/packages/contracts/src/command-catalog.ts +116 -0
  4. package/packages/contracts/src/commands.ts +5 -4
  5. package/packages/contracts/src/daemon-events.ts +2 -1
  6. package/packages/contracts/src/index.ts +2 -0
  7. package/packages/contracts/src/plain-text.ts +61 -0
  8. package/packages/daemon/dist/command-center/command-catalog-routes.js +78 -0
  9. package/packages/daemon/dist/command-center/plugin-routes.js +84 -0
  10. package/packages/daemon/dist/command-center/server.js +13 -0
  11. package/packages/daemon/dist/lib/cli-action-bridge.js +15 -0
  12. package/packages/daemon/dist/lib/daemon-embed.js +24 -1
  13. package/packages/daemon/dist/lib/headless-daemon.js +1 -0
  14. package/packages/daemon/dist/lib/worktree.js +18 -0
  15. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  16. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  17. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  18. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  19. package/packages/daemon/dist/plugins/action-catalog.js +129 -0
  20. package/packages/daemon/dist/plugins/action-cli.js +212 -0
  21. package/packages/daemon/dist/plugins/api-table.js +303 -0
  22. package/packages/daemon/dist/plugins/cli.js +556 -0
  23. package/packages/daemon/dist/plugins/consent.js +107 -0
  24. package/packages/daemon/dist/plugins/daemon-plugins.js +132 -0
  25. package/packages/daemon/dist/plugins/discovery.js +142 -0
  26. package/packages/daemon/dist/plugins/examples/worktree-tasks.js +115 -0
  27. package/packages/daemon/dist/plugins/exec-sandbox.js +202 -0
  28. package/packages/daemon/dist/plugins/host/actions-prelude.js +279 -0
  29. package/packages/daemon/dist/plugins/host/entry.js +4 -0
  30. package/packages/daemon/dist/plugins/host/host-api-prelude.js +232 -0
  31. package/packages/daemon/dist/plugins/host/lua-state.js +493 -0
  32. package/packages/daemon/dist/plugins/host/main.js +322 -0
  33. package/packages/daemon/dist/plugins/host/sandbox.js +299 -0
  34. package/packages/daemon/dist/plugins/host-calls.js +279 -0
  35. package/packages/daemon/dist/plugins/manifest.js +69 -0
  36. package/packages/daemon/dist/plugins/plugin-exec.js +261 -0
  37. package/packages/daemon/dist/plugins/plugin-log.js +54 -0
  38. package/packages/daemon/dist/plugins/plugin-store.js +74 -0
  39. package/packages/daemon/dist/plugins/protocol.js +252 -0
  40. package/packages/daemon/dist/plugins/safe-files.js +97 -0
  41. package/packages/daemon/dist/plugins/supervisor.js +790 -0
  42. package/packages/daemon/dist/plugins/worktree-calls.js +154 -0
  43. package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +27 -0
  44. package/packages/daemon/dist/tui/mirror/runtime/application-home-experience.js +2 -0
  45. package/packages/daemon/dist/tui/mirror/runtime/application-palette-command-owner.js +30 -2
  46. package/packages/daemon/dist/tui/mirror/runtime/application-plugin-commands.js +152 -0
  47. package/packages/daemon/dist/tui/mirror/runtime/application-plugin-form.js +251 -0
  48. package/packages/daemon/dist/tui/mirror/workspace/application-command-description.js +14 -0
  49. package/packages/daemon/dist/tui/mirror/workspace/palette-list-layout.js +5 -0
  50. package/packages/daemon/src/command-center/command-catalog-routes.ts +116 -0
  51. package/packages/daemon/src/command-center/plugin-routes.ts +110 -0
  52. package/packages/daemon/src/command-center/server.ts +15 -0
  53. package/packages/daemon/src/lib/cli-action-bridge.ts +19 -0
  54. package/packages/daemon/src/lib/daemon-embed.ts +42 -0
  55. package/packages/daemon/src/lib/headless-daemon.ts +1 -0
  56. package/packages/daemon/src/lib/worktree.ts +16 -0
  57. package/packages/daemon/src/plugins/action-catalog.ts +141 -0
  58. package/packages/daemon/src/plugins/action-cli.ts +248 -0
  59. package/packages/daemon/src/plugins/api-table.ts +346 -0
  60. package/packages/daemon/src/plugins/cli.ts +630 -0
  61. package/packages/daemon/src/plugins/consent.ts +125 -0
  62. package/packages/daemon/src/plugins/daemon-plugins.ts +182 -0
  63. package/packages/daemon/src/plugins/discovery.ts +176 -0
  64. package/packages/daemon/src/plugins/examples/worktree-tasks.ts +120 -0
  65. package/packages/daemon/src/plugins/exec-sandbox.ts +264 -0
  66. package/packages/daemon/src/plugins/host/actions-prelude.ts +280 -0
  67. package/packages/daemon/src/plugins/host/entry.ts +5 -0
  68. package/packages/daemon/src/plugins/host/host-api-prelude.ts +233 -0
  69. package/packages/daemon/src/plugins/host/lua-state.ts +557 -0
  70. package/packages/daemon/src/plugins/host/main.ts +359 -0
  71. package/packages/daemon/src/plugins/host/sandbox.ts +301 -0
  72. package/packages/daemon/src/plugins/host-calls.ts +343 -0
  73. package/packages/daemon/src/plugins/manifest.ts +74 -0
  74. package/packages/daemon/src/plugins/plugin-exec.ts +326 -0
  75. package/packages/daemon/src/plugins/plugin-log.ts +63 -0
  76. package/packages/daemon/src/plugins/plugin-store.ts +80 -0
  77. package/packages/daemon/src/plugins/protocol.ts +275 -0
  78. package/packages/daemon/src/plugins/safe-files.ts +105 -0
  79. package/packages/daemon/src/plugins/supervisor.ts +954 -0
  80. package/packages/daemon/src/plugins/worktree-calls.ts +183 -0
  81. package/packages/daemon/src/tui/mirror/runtime/application-fleet-switcher.tsx +3 -1
  82. package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +32 -0
  83. package/packages/daemon/src/tui/mirror/runtime/application-home-experience.ts +2 -0
  84. package/packages/daemon/src/tui/mirror/runtime/application-palette-command-owner.ts +42 -2
  85. package/packages/daemon/src/tui/mirror/runtime/application-palette-preview.tsx +7 -1
  86. package/packages/daemon/src/tui/mirror/runtime/application-plugin-commands.ts +229 -0
  87. package/packages/daemon/src/tui/mirror/runtime/application-plugin-form.ts +312 -0
  88. package/packages/daemon/src/tui/mirror/workspace/application-command-description.ts +44 -2
  89. package/packages/daemon/src/tui/mirror/workspace/palette-list-layout.ts +4 -0
@@ -0,0 +1,129 @@
1
+ /**
2
+ * The plugin half of the command catalog: the actions each loaded plugin
3
+ * registered with `ide.action.register`, as catalog entries.
4
+ *
5
+ * A plugin's actions are replaced wholesale every time it publishes, and
6
+ * dropped when it unloads, is disabled, loses consent or its host exits.
7
+ */
8
+ import { COMMAND_PROTOCOL_VERSION, CommandCatalogEntrySchemaZ, CommandParamSchemaZ, plainTextSchema, } from "@tmux-ide/contracts";
9
+ import { z } from "zod";
10
+ import { MAX_ACTIONS_PER_PLUGIN, MAX_LOCAL_ACTION_ID } from "./host/actions-prelude.js";
11
+ /** What the host publishes for one action (plugin-local id). */
12
+ const PublishedActionSchemaZ = z
13
+ .object({
14
+ // "plugin." + a 63-character plugin name + "." + 80 = 151, under the
15
+ // catalog's 160-character id limit.
16
+ id: z
17
+ .string()
18
+ .regex(/^[a-z][a-z0-9-]*(?:\.[a-z0-9-]+)*$/u)
19
+ .max(MAX_LOCAL_ACTION_ID),
20
+ title: plainTextSchema(1, 160),
21
+ category: plainTextSchema(1, 80),
22
+ description: plainTextSchema(1, 500).optional(),
23
+ dangerous: z.boolean(),
24
+ params: z.array(CommandParamSchemaZ).max(32),
25
+ })
26
+ .strict();
27
+ const PublishedActionsSchemaZ = z.array(PublishedActionSchemaZ).max(MAX_ACTIONS_PER_PLUGIN);
28
+ /** `plugin.<plugin>.<local id>`: the catalog id of a plugin action. */
29
+ export function pluginCommandId(plugin, action) {
30
+ return `plugin.${plugin}.${action}`;
31
+ }
32
+ /** Split a catalog id back into plugin and local action id, or null. */
33
+ export function parsePluginCommandId(id) {
34
+ const match = /^plugin\.([a-z][a-z0-9-]{0,62})\.(.+)$/u.exec(id);
35
+ return match ? { plugin: match[1], action: match[2] } : null;
36
+ }
37
+ export class PluginActionCatalog {
38
+ #byPlugin = new Map();
39
+ #onChange;
40
+ #revision = 0;
41
+ constructor(onChange = () => { }) {
42
+ this.#onChange = onChange;
43
+ }
44
+ get revision() {
45
+ return this.#revision;
46
+ }
47
+ /**
48
+ * Replace `plugin`'s actions from the JSON text it published. Returns an
49
+ * error message, without changing anything, if the list is malformed.
50
+ */
51
+ publish(plugin, json) {
52
+ let raw;
53
+ try {
54
+ raw = JSON.parse(json);
55
+ }
56
+ catch {
57
+ return "published actions are not JSON";
58
+ }
59
+ // Lua's encoder writes an empty table as [] and omits nil fields, which
60
+ // is exactly the shape the schema expects.
61
+ const parsed = PublishedActionsSchemaZ.safeParse(raw);
62
+ if (!parsed.success) {
63
+ const issue = parsed.error.issues[0];
64
+ return `published actions are invalid at ${issue?.path.join(".") ?? "?"}: ${issue?.message ?? ""}`;
65
+ }
66
+ const built = parsed.data.map((action) => CommandCatalogEntrySchemaZ.safeParse({
67
+ descriptor: {
68
+ version: COMMAND_PROTOCOL_VERSION,
69
+ id: pluginCommandId(plugin, action.id),
70
+ owner: "plugin",
71
+ label: action.title,
72
+ ...(action.description ? { description: action.description } : {}),
73
+ category: action.category,
74
+ schemas: { input: `plugin:${plugin}` },
75
+ dangerous: action.dangerous,
76
+ confirmation: action.dangerous ? "dialog" : "none",
77
+ },
78
+ plugin,
79
+ params: action.params,
80
+ }));
81
+ // All or nothing: one bad entry refuses the whole list, and nothing in
82
+ // plugin output can throw out of here into the daemon.
83
+ const entries = [];
84
+ for (const result of built) {
85
+ if (!result.success) {
86
+ const issue = result.error.issues[0];
87
+ return `published actions are invalid at ${issue?.path.join(".") ?? "?"}: ${issue?.message ?? ""}`;
88
+ }
89
+ entries.push(result.data);
90
+ }
91
+ const previous = this.#byPlugin.get(plugin) ?? [];
92
+ if (entries.length === 0 && previous.length === 0)
93
+ return null;
94
+ if (JSON.stringify(previous) === JSON.stringify(entries))
95
+ return null;
96
+ if (entries.length === 0)
97
+ this.#byPlugin.delete(plugin);
98
+ else
99
+ this.#byPlugin.set(plugin, entries);
100
+ this.#changed();
101
+ return null;
102
+ }
103
+ /** Drop every action of `plugin`. */
104
+ drop(plugin) {
105
+ if (!this.#byPlugin.delete(plugin))
106
+ return;
107
+ this.#changed();
108
+ }
109
+ /** Drop everything, e.g. when the host exits; plugins publish again on load. */
110
+ clear() {
111
+ if (this.#byPlugin.size === 0)
112
+ return;
113
+ this.#byPlugin.clear();
114
+ this.#changed();
115
+ }
116
+ entries() {
117
+ return [...this.#byPlugin.keys()].sort().flatMap((plugin) => this.#byPlugin.get(plugin) ?? []);
118
+ }
119
+ find(id) {
120
+ const parsed = parsePluginCommandId(id);
121
+ if (!parsed)
122
+ return undefined;
123
+ return this.#byPlugin.get(parsed.plugin)?.find((entry) => entry.descriptor.id === id);
124
+ }
125
+ #changed() {
126
+ this.#revision += 1;
127
+ this.#onChange();
128
+ }
129
+ }
@@ -0,0 +1,212 @@
1
+ /**
2
+ * `tmux-ide action list` and `tmux-ide action run`: the command catalog from
3
+ * a shell, and the way tmux key bindings reach plugin actions.
4
+ */
5
+ import { parseArgs } from "node:util";
6
+ import { callDaemon, formatValue, PluginCliError, terminalSafeIo, } from "./cli.js";
7
+ export const ACTION_USAGE = `Usage:
8
+ tmux-ide action list [--json] List built-in and plugin commands
9
+ tmux-ide action run <id> [--arg name=value]… [--yes] [--json]
10
+ Run a plugin command (plugin.<plugin>.<id>)
11
+ tmux-ide action run <id> --input '<json>' Run a built-in command with its JSON input
12
+ Options for run:
13
+ --session <name> --pane <id> Where to act (default: this pane, from $TMUX_PANE)
14
+ --yes Confirm a dangerous command without a prompt`;
15
+ function describeParam(param) {
16
+ const choices = param.choices?.length
17
+ ? ` (${param.choices.map((choice) => choice.value).join(", ")})`
18
+ : param.dynamicChoices
19
+ ? " (choices from the plugin)"
20
+ : "";
21
+ const fallback = param.default !== undefined
22
+ ? `, default ${JSON.stringify(param.default)}`
23
+ : param.dynamicDefault
24
+ ? ", default from the plugin"
25
+ : "";
26
+ return `${param.name}: ${param.type}${param.required ? "" : "?"}${choices}${fallback}`;
27
+ }
28
+ export function formatCatalog(catalog) {
29
+ const plugins = catalog.entries.filter((entry) => entry.plugin);
30
+ const builtins = catalog.entries.filter((entry) => !entry.plugin);
31
+ const lines = [];
32
+ const section = (title, entries) => {
33
+ if (entries.length === 0)
34
+ return;
35
+ if (lines.length > 0)
36
+ lines.push("");
37
+ lines.push(title);
38
+ const width = Math.max(...entries.map((entry) => entry.descriptor.id.length));
39
+ for (const entry of entries) {
40
+ const flag = entry.descriptor.dangerous ? " [asks to confirm]" : "";
41
+ lines.push(` ${entry.descriptor.id.padEnd(width)} ${entry.descriptor.label}${flag}`);
42
+ for (const param of entry.params)
43
+ lines.push(` ${" ".repeat(width)} ${describeParam(param)}`);
44
+ }
45
+ };
46
+ section("Plugin commands", plugins);
47
+ section("Built-in commands (take --input JSON)", builtins);
48
+ if (lines.length === 0)
49
+ lines.push("No commands.");
50
+ return lines.join("\n");
51
+ }
52
+ /** Turn `--arg name=value` strings into typed arguments for `entry`. */
53
+ export function parseActionArgs(entry, raw) {
54
+ const out = {};
55
+ for (const item of raw) {
56
+ const eq = item.indexOf("=");
57
+ if (eq <= 0)
58
+ throw new PluginCliError(`--arg expects name=value, got '${item}'`, 2);
59
+ const name = item.slice(0, eq);
60
+ const value = item.slice(eq + 1);
61
+ const param = entry.params.find((candidate) => candidate.name === name);
62
+ if (!param) {
63
+ const known = entry.params.map((candidate) => candidate.name).join(", ") || "none";
64
+ throw new PluginCliError(`'${entry.descriptor.id}' has no parameter '${name}' (it takes: ${known})`, 2);
65
+ }
66
+ if (name in out)
67
+ throw new PluginCliError(`--arg ${name} is given twice`, 2);
68
+ if (param.type === "number") {
69
+ const number = Number(value);
70
+ if (value.trim() === "" || !Number.isFinite(number))
71
+ throw new PluginCliError(`${name} must be a number`, 2);
72
+ out[name] = number;
73
+ }
74
+ else if (param.type === "boolean") {
75
+ if (value !== "true" && value !== "false")
76
+ throw new PluginCliError(`${name} must be true or false`, 2);
77
+ out[name] = value === "true";
78
+ }
79
+ else {
80
+ out[name] = value;
81
+ }
82
+ }
83
+ return out;
84
+ }
85
+ export async function runActionCli(argv, rawIo) {
86
+ const io = terminalSafeIo(rawIo);
87
+ try {
88
+ return await actionCli(argv, io);
89
+ }
90
+ catch (error) {
91
+ if (error instanceof PluginCliError) {
92
+ io.err(error.message);
93
+ return error.exitCode;
94
+ }
95
+ if (error instanceof TypeError &&
96
+ "code" in error &&
97
+ String(error.code).startsWith("ERR_PARSE_ARGS")) {
98
+ io.err(`${error.message}\n${ACTION_USAGE}`);
99
+ return 2;
100
+ }
101
+ if (error instanceof Error && error.name === "CliActionInvocationError") {
102
+ io.err(error.message);
103
+ return 1;
104
+ }
105
+ throw error;
106
+ }
107
+ }
108
+ /**
109
+ * Whether `entry` may run: commands that are not dangerous always may; a
110
+ * dangerous one needs --yes or a "y" from the person at the terminal.
111
+ */
112
+ async function confirmDangerous(entry, yes, io) {
113
+ if (!entry.descriptor.dangerous || yes)
114
+ return true;
115
+ if (!io.interactive())
116
+ throw new PluginCliError(`'${entry.descriptor.label}' asks to confirm: pass --yes.`, 2);
117
+ const answer = (await io.ask(`${entry.descriptor.label}: are you sure? [y/N] `))
118
+ .trim()
119
+ .toLowerCase();
120
+ return answer === "y" || answer === "yes";
121
+ }
122
+ async function actionCli(argv, io) {
123
+ const [sub, ...rest] = argv;
124
+ const { values, positionals } = parseArgs({
125
+ args: [...rest],
126
+ allowPositionals: true,
127
+ strict: true,
128
+ options: {
129
+ json: { type: "boolean" },
130
+ yes: { type: "boolean", short: "y" },
131
+ arg: { type: "string", short: "a", multiple: true },
132
+ input: { type: "string" },
133
+ session: { type: "string" },
134
+ pane: { type: "string" },
135
+ help: { type: "boolean", short: "h" },
136
+ },
137
+ });
138
+ if (values.help || sub === "help" || sub === "--help" || sub === "-h") {
139
+ io.out(ACTION_USAGE);
140
+ return 0;
141
+ }
142
+ if (!sub)
143
+ throw new PluginCliError(ACTION_USAGE, 2);
144
+ if (sub === "list") {
145
+ const catalog = await callDaemon(io, "GET", "/api/resources/command-catalog");
146
+ io.out(values.json ? JSON.stringify(catalog, null, 2) : formatCatalog(catalog));
147
+ return 0;
148
+ }
149
+ if (sub !== "run")
150
+ throw new PluginCliError(`Unknown action command '${sub}'.\n${ACTION_USAGE}`, 2);
151
+ const id = positionals[0];
152
+ if (!id || positionals.length > 1)
153
+ throw new PluginCliError(`Name one command to run.\n${ACTION_USAGE}`, 2);
154
+ if (!id.startsWith("plugin.")) {
155
+ if (values.arg?.length)
156
+ throw new PluginCliError("Built-in commands take --input JSON, not --arg.", 2);
157
+ let input = {};
158
+ if (values.input !== undefined) {
159
+ try {
160
+ input = JSON.parse(values.input);
161
+ }
162
+ catch {
163
+ throw new PluginCliError("--input must be JSON.", 2);
164
+ }
165
+ }
166
+ const catalog = await callDaemon(io, "GET", "/api/resources/command-catalog");
167
+ const entry = catalog.entries.find((candidate) => candidate.descriptor.id === id);
168
+ if (entry && !(await confirmDangerous(entry, values.yes === true, io))) {
169
+ io.out("Cancelled.");
170
+ return 1;
171
+ }
172
+ const result = await io.dispatchBuiltin(id, input);
173
+ io.out(values.json ? JSON.stringify(result, null, 2) : formatValue(result));
174
+ return 0;
175
+ }
176
+ if (values.input !== undefined)
177
+ throw new PluginCliError("Plugin commands take --arg name=value.", 2);
178
+ const catalog = await callDaemon(io, "GET", "/api/resources/command-catalog");
179
+ const entry = catalog.entries.find((candidate) => candidate.descriptor.id === id);
180
+ if (!entry)
181
+ throw new PluginCliError(`No command named '${id}'. See \`tmux-ide action list\`.`);
182
+ const args = parseActionArgs(entry, values.arg ?? []);
183
+ const confirmed = await confirmDangerous(entry, values.yes === true, io);
184
+ if (!confirmed) {
185
+ io.out("Cancelled.");
186
+ return 1;
187
+ }
188
+ const pane = values.pane ?? io.tmuxPane();
189
+ // Inside tmux, the session defaults to this pane's.
190
+ const session = values.session ?? (pane ? io.tmuxSession?.(pane) : undefined);
191
+ const result = await callDaemon(io, "POST", "/api/v2/commands/invoke", {
192
+ id,
193
+ args,
194
+ context: {
195
+ source: "cli",
196
+ ...(session ? { session } : {}),
197
+ ...(pane ? { pane } : {}),
198
+ },
199
+ ...(entry.descriptor.dangerous ? { confirmed: true } : {}),
200
+ });
201
+ if (values.json) {
202
+ io.out(JSON.stringify(result, null, 2));
203
+ return result.ok ? 0 : 1;
204
+ }
205
+ if (!result.ok) {
206
+ io.err(result.error);
207
+ return 1;
208
+ }
209
+ if (result.value !== undefined)
210
+ io.out(formatValue(result.value));
211
+ return 0;
212
+ }
@@ -0,0 +1,303 @@
1
+ /**
2
+ * The Lua API, described once. `tmux-ide lua api`, `tmux-ide lua describe`
3
+ * and the generated docs read this table, and a test checks that the host's
4
+ * `ide` table has exactly these entries, so the three cannot drift apart.
5
+ */
6
+ import { PLUGIN_API_VERSION } from "./protocol.js";
7
+ const v1 = { since: "1.0", stability: "stable" };
8
+ const LOG_DETAILS = "Writes one line to `~/.tmux-ide/logs/plugins.log` and the daemon's `plugins` log channel, " +
9
+ "tagged with the plugin's name. `fields` is a table encoded as JSON. Each plugin may log " +
10
+ "100 lines per second; extra lines are dropped and counted.";
11
+ export const API_ENTRIES = Object.freeze([
12
+ {
13
+ name: "ide.api",
14
+ kind: "value",
15
+ signature: "ide.api",
16
+ summary: `The Lua API version this tmux-ide provides, currently "${PLUGIN_API_VERSION}".`,
17
+ details: "Minor versions only add. A plugin declares the versions it works with in its manifest's `api` field.",
18
+ ...v1,
19
+ },
20
+ {
21
+ name: "ide.version",
22
+ kind: "value",
23
+ signature: "ide.version",
24
+ summary: "The tmux-ide version running the script.",
25
+ ...v1,
26
+ },
27
+ {
28
+ name: "ide.plugin.name",
29
+ kind: "value",
30
+ signature: "ide.plugin.name",
31
+ summary: 'The running plugin\'s name; "init" for ~/.tmux-ide/init.lua, "run" for `tmux-ide lua run`.',
32
+ ...v1,
33
+ },
34
+ {
35
+ name: "ide.settings",
36
+ kind: "value",
37
+ signature: "ide.settings",
38
+ summary: "The plugin's settings: the defaults declared in its manifest.",
39
+ ...v1,
40
+ },
41
+ {
42
+ name: "ide.has",
43
+ kind: "function",
44
+ signature: "ide.has(feature) -> boolean",
45
+ summary: "Whether this tmux-ide provides an API feature, so a plugin can degrade without raising its `api` range.",
46
+ details: "Features in 1.0: log, include, require, actions, exec, panes, timers, json, store, notify.",
47
+ example: 'if ide.has("include") then ide.include("keys.lua") end',
48
+ ...v1,
49
+ },
50
+ {
51
+ name: "ide.log.debug",
52
+ kind: "function",
53
+ signature: "ide.log.debug(message, fields?)",
54
+ summary: "Log a debug line.",
55
+ details: LOG_DETAILS,
56
+ ...v1,
57
+ },
58
+ {
59
+ name: "ide.log.info",
60
+ kind: "function",
61
+ signature: "ide.log.info(message, fields?)",
62
+ summary: "Log an info line.",
63
+ details: LOG_DETAILS,
64
+ example: 'ide.log.info("loaded", { tasks = 3 })',
65
+ ...v1,
66
+ },
67
+ {
68
+ name: "ide.log.warn",
69
+ kind: "function",
70
+ signature: "ide.log.warn(message, fields?)",
71
+ summary: "Log a warning.",
72
+ details: LOG_DETAILS,
73
+ ...v1,
74
+ },
75
+ {
76
+ name: "ide.log.error",
77
+ kind: "function",
78
+ signature: "ide.log.error(message, fields?)",
79
+ summary: "Log an error.",
80
+ details: LOG_DETAILS,
81
+ ...v1,
82
+ },
83
+ {
84
+ name: "ide.include",
85
+ kind: "function",
86
+ signature: "ide.include(file) -> ...",
87
+ summary: "Run another .lua file and return what it returns.",
88
+ details: "`init.lua` includes from `~/.tmux-ide/` and `~/.tmux-ide/lua/`; a plugin includes from its own " +
89
+ "directory. Names must be relative and may not leave those directories. Files over 1 MiB are refused.",
90
+ errors: ["E_INVALID", "E_NOT_FOUND", "E_DENIED"],
91
+ example: 'ide.include("keys.lua")',
92
+ ...v1,
93
+ },
94
+ {
95
+ name: "ide.action.register",
96
+ kind: "function",
97
+ signature: "ide.action.register{ id, title, run, category?, description?, dangerous?, params? }",
98
+ summary: "Offer a named action in the command palette and to `tmux-ide action run plugin.<plugin>.<id>`.",
99
+ details: "`run(ctx, args)` runs when the action is invoked; `ctx` has `source` (palette, cli, key…) and, " +
100
+ "when known, `session`, `window` and `pane`. Each param is `{ name, type, label?, description?, " +
101
+ "optional?, pattern?, choices?, default? }`, where type is string, text, number, boolean or choice, " +
102
+ "`pattern` is a Lua pattern, and `choices` and `default` may be functions of `ctx`. Arguments are " +
103
+ "checked before `run` is called. `dangerous = true` makes every caller confirm first. Registering " +
104
+ "an id again replaces it. At most 200 actions per plugin, 32 params per action.",
105
+ errors: ["E_INVALID"],
106
+ example: 'ide.action.register{ id = "hello", title = "Say hello", params = { { name = "who" } }, ' +
107
+ 'run = function(ctx, args) ide.log.info("hello " .. args.who) end }',
108
+ ...v1,
109
+ },
110
+ {
111
+ name: "ide.action.unregister",
112
+ kind: "function",
113
+ signature: "ide.action.unregister(id) -> boolean",
114
+ summary: "Remove an action this plugin registered; false if there was none.",
115
+ ...v1,
116
+ },
117
+ {
118
+ name: "ide.exec",
119
+ kind: "function",
120
+ signature: "ide.exec{ cmd, args?, cwd?, env?, stdin?, timeout_ms?, context?, shell? } -> { code, signal, stdout, stderr, timed_out, truncated }",
121
+ summary: "Run a program the manifest lists under capabilities.exec, and wait for it.",
122
+ details: "`cmd` is a program name looked up on PATH; `args` are passed as they are, with no shell. " +
123
+ "`shell = true` runs `cmd` as a /bin/sh command line and needs capabilities.shell. " +
124
+ '`context` is a tmux pane id like "%3": the program gets that pane\'s cwd, TMUX and ' +
125
+ "TMUX_PANE, and needs capabilities `panes.send`. `cmd` is looked up on the daemon's PATH; " +
126
+ "`env` may set only LANG, LC_*, TZ, TERM, colour variables, COLUMNS, LINES and PLUGIN_*. " +
127
+ "A program can usually do anything your account can; the OS sandbox only keeps it from " +
128
+ "writing tmux-ide's state (but ~/.tmux-ide/plugin-data/<plugin>), reading the daemon's " +
129
+ "credentials and, without `panes.send`, reaching your tmux server. On Linux it is off unless the daemon has TMUX_IDE_PLUGIN_EXEC_LINUX=1 (untested). " +
130
+ "It is killed with everything it started after `timeout_ms` (default and most: the " +
131
+ "callback's 30 s wall clock), or when the plugin fails or unloads, and keeps at most " +
132
+ "1 MiB of each output. Output is redacted.",
133
+ errors: ["E_DENIED", "E_INVALID", "E_NOT_FOUND", "E_UNAVAILABLE"],
134
+ example: 'local r = ide.exec{ cmd = "git", args = { "status", "--short" }, context = ctx.pane }',
135
+ ...v1,
136
+ },
137
+ {
138
+ name: "ide.panes",
139
+ kind: "function",
140
+ signature: "ide.panes{ session?, workspace? } -> { pane… }",
141
+ summary: "The panes tmux-ide manages, as pane objects.",
142
+ details: "A pane has `id`, `workspace`, `session` and `title`, and methods `read()`, " +
143
+ '`send(text, { enter = true })`, `split{ dir = "right"|"down", title? }`, `zoom(on?)`, ' +
144
+ "`focus()`, `rename(name)`, `kill()`, `rename_window(name)` and `kill_window()`. They go " +
145
+ "through the same daemon actions and automation API as the app and the CLI. `send` needs " +
146
+ "capabilities `panes.send`.",
147
+ example: 'for _, pane in ipairs(ide.panes{ session = "demo" }) do print(pane.title) end',
148
+ ...v1,
149
+ },
150
+ {
151
+ name: "ide.session",
152
+ kind: "function",
153
+ signature: "ide.session(workspace) -> { rename(name), kill() }",
154
+ summary: "A workspace's tmux session, to rename or kill.",
155
+ ...v1,
156
+ },
157
+ {
158
+ name: "ide.worktree.list",
159
+ kind: "function",
160
+ signature: "ide.worktree.list{ session } -> { repo, worktrees = { { path, branch, primary, session, running, status }… } }",
161
+ summary: "The git worktrees of a session's repository, with their sessions.",
162
+ details: "Needs capabilities `worktree`. `session` is a tmux session name (usually `ctx.session`); " +
163
+ "the daemon runs tmux-ide's own worktree code for that session's repository.",
164
+ errors: ["E_DENIED", "E_INVALID", "E_NOT_FOUND", "E_FAILED"],
165
+ example: "local tasks = ide.worktree.list{ session = ctx.session }",
166
+ ...v1,
167
+ },
168
+ {
169
+ name: "ide.worktree.create",
170
+ kind: "function",
171
+ signature: "ide.worktree.create{ session, branch, from? } -> { branch, path, session }",
172
+ summary: "Add a worktree on a new branch (or an existing one) and open a plain session in it.",
173
+ details: "Needs capabilities `worktree`. `branch` and `from` must be plain git names: letters, " +
174
+ "digits and `. _ / -`, not starting with `-` or `.`.",
175
+ errors: ["E_DENIED", "E_INVALID", "E_NOT_FOUND", "E_FAILED"],
176
+ example: 'ide.worktree.create{ session = ctx.session, branch = "fix-login" }',
177
+ ...v1,
178
+ },
179
+ {
180
+ name: "ide.worktree.open",
181
+ kind: "function",
182
+ signature: "ide.worktree.open{ session, branch } -> { branch, path, session, created }",
183
+ summary: "Open (or start) the session of an existing worktree.",
184
+ details: "Needs capabilities `worktree`. Sessions it starts are plain: the worktree's own tmux-ide " +
185
+ "layout, whose commands come from that branch, never runs from a plugin, and git runs " +
186
+ "with hooks off.",
187
+ errors: ["E_DENIED", "E_INVALID", "E_NOT_FOUND", "E_FAILED"],
188
+ ...v1,
189
+ },
190
+ {
191
+ name: "ide.worktree.remove",
192
+ kind: "function",
193
+ signature: "ide.worktree.remove{ session, branch } -> { branch, path, sessionKilled, removed }",
194
+ summary: "Close a worktree's session and remove the worktree; refused if it has changes.",
195
+ details: "Needs capabilities `worktree`. Never forces: a worktree with changes is refused. Mark " +
196
+ "actions that call it `dangerous = true`, so a person confirms them.",
197
+ errors: ["E_DENIED", "E_INVALID", "E_NOT_FOUND", "E_FAILED"],
198
+ ...v1,
199
+ },
200
+ {
201
+ name: "ide.notify",
202
+ kind: "function",
203
+ signature: "ide.notify(text, { level? })",
204
+ summary: "Show a short message (200 characters) in every attached client's status line.",
205
+ ...v1,
206
+ },
207
+ {
208
+ name: "ide.json.encode",
209
+ kind: "function",
210
+ signature: "ide.json.encode(value) -> string",
211
+ summary: "Encode a Lua value as JSON. Tables that contain themselves are refused.",
212
+ ...v1,
213
+ },
214
+ {
215
+ name: "ide.json.decode",
216
+ kind: "function",
217
+ signature: "ide.json.decode(text) -> value",
218
+ summary: "Decode JSON text. null becomes nil.",
219
+ errors: ["E_INVALID"],
220
+ ...v1,
221
+ },
222
+ {
223
+ name: "ide.store.get",
224
+ kind: "function",
225
+ signature: "ide.store.get(key) -> value | nil",
226
+ summary: "Read a value this plugin stored.",
227
+ details: "Each plugin has its own store, kept across restarts: at most 1000 keys and 1 MiB.",
228
+ ...v1,
229
+ },
230
+ {
231
+ name: "ide.store.set",
232
+ kind: "function",
233
+ signature: "ide.store.set(key, value)",
234
+ summary: "Store a JSON-able value under `key`; nil deletes it.",
235
+ errors: ["E_INVALID", "E_LIMIT"],
236
+ ...v1,
237
+ },
238
+ {
239
+ name: "ide.store.delete",
240
+ kind: "function",
241
+ signature: "ide.store.delete(key)",
242
+ summary: "Delete a stored value.",
243
+ ...v1,
244
+ },
245
+ {
246
+ name: "ide.store.keys",
247
+ kind: "function",
248
+ signature: "ide.store.keys() -> { key… }",
249
+ summary: "The stored keys, sorted.",
250
+ ...v1,
251
+ },
252
+ {
253
+ name: "ide.timer.after",
254
+ kind: "function",
255
+ signature: "ide.timer.after(ms, fn) -> { id, cancel() }",
256
+ summary: "Call `fn` once after `ms` milliseconds, under the callback budget.",
257
+ details: "At most 64 timers per plugin. Unloading or reloading the plugin cancels them. After a " +
258
+ "timer callback that took t ms, the plugin's next timer waits at least max(t, 10 ms).",
259
+ ...v1,
260
+ },
261
+ {
262
+ name: "ide.timer.every",
263
+ kind: "function",
264
+ signature: "ide.timer.every(ms, fn) -> { id, cancel() }",
265
+ summary: "Call `fn` every `ms` milliseconds (at least 250).",
266
+ ...v1,
267
+ },
268
+ {
269
+ name: "require",
270
+ kind: "global",
271
+ signature: "require(module) -> value",
272
+ summary: "Load a module once and cache it: `a.b` reads `a/b.lua` or `a/b/init.lua`.",
273
+ details: "A plugin searches only its own directory, which its consent covers; `init.lua` searches `~/.tmux-ide/lua/`.",
274
+ errors: ["E_INVALID", "E_NOT_FOUND", "E_DENIED"],
275
+ ...v1,
276
+ },
277
+ {
278
+ name: "print",
279
+ kind: "global",
280
+ signature: "print(...)",
281
+ summary: "Same as ide.log.info with the arguments joined by tabs.",
282
+ ...v1,
283
+ },
284
+ {
285
+ name: "load",
286
+ kind: "global",
287
+ signature: "load(source, name?, mode?, env?) -> function | nil, error",
288
+ summary: "Compile Lua source text. Bytecode and reader functions are refused.",
289
+ ...v1,
290
+ },
291
+ ]);
292
+ /** The `ide.*` names the host must bind (globals are checked separately). */
293
+ export function ideTableNames() {
294
+ return API_ENTRIES.filter((entry) => entry.name.startsWith("ide.")).map((entry) => entry.name);
295
+ }
296
+ export function findApiEntry(name) {
297
+ return API_ENTRIES.find((entry) => entry.name === name);
298
+ }
299
+ /** Close matches for an unknown name, for "did you mean" hints. */
300
+ export function suggestApiEntries(name) {
301
+ const needle = name.toLowerCase();
302
+ return API_ENTRIES.filter((entry) => entry.name.toLowerCase().includes(needle)).slice(0, 5);
303
+ }