tmux-ide 2.9.18 → 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.
- package/bin/cli.js +14703 -3882
- 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 +2 -0
- package/packages/contracts/src/plain-text.ts +61 -0
- 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/doctor.js +12 -5
- package/packages/daemon/dist/lib/cli-action-bridge.js +15 -0
- package/packages/daemon/dist/lib/daemon-embed.js +24 -1
- package/packages/daemon/dist/lib/headless-daemon.js +1 -0
- package/packages/daemon/dist/lib/native-split-capability.js +13 -15
- 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/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 +132 -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/terminal/mirror/session-channel.js +3 -2
- package/packages/daemon/dist/terminal/mirror/window-split-authority.js +1 -1
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +27 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-experience.js +2 -0
- 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/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/doctor.ts +12 -5
- package/packages/daemon/src/lib/cli-action-bridge.ts +19 -0
- package/packages/daemon/src/lib/daemon-embed.ts +42 -0
- package/packages/daemon/src/lib/headless-daemon.ts +1 -0
- package/packages/daemon/src/lib/native-split-capability.ts +12 -13
- package/packages/daemon/src/lib/worktree.ts +16 -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 +182 -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/terminal/mirror/session-channel.ts +3 -2
- package/packages/daemon/src/terminal/mirror/window-split-authority.ts +3 -2
- package/packages/daemon/src/tui/mirror/runtime/application-fleet-switcher.tsx +3 -1
- package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +32 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-experience.ts +2 -0
- 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/workspace/application-command-description.ts +44 -2
- package/packages/daemon/src/tui/mirror/workspace/palette-list-layout.ts +4 -0
|
@@ -80,23 +80,21 @@ export function createNativeSplitReadiness(options) {
|
|
|
80
80
|
pending = null;
|
|
81
81
|
}));
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* timeout, a lost server or any other failure says nothing, so it
|
|
83
|
+
/** True only when the selected server refuses `tmux-ide-resize-split` by name: a
|
|
84
|
+
* stock tmux, or a tmux-ide tmux built before that command, which may still have
|
|
85
|
+
* the journal. A timeout, a lost server or any other failure says nothing, so it
|
|
86
|
+
* stays false. */
|
|
86
87
|
export function createStockSplitProbe(options) {
|
|
88
|
+
const command = "tmux-ide-resize-split";
|
|
87
89
|
return async () => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (!new RegExp(`^unknown command: ${command}$`, "mu").test(text))
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
90
|
+
try {
|
|
91
|
+
await options.runPinnedTmux([command, "-V"]);
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
const failure = error;
|
|
96
|
+
const text = String(failure?.cause?.stderr ?? failure?.stderr ?? "");
|
|
97
|
+
return new RegExp(`^unknown command: ${command}$`, "mu").test(text);
|
|
99
98
|
}
|
|
100
|
-
return true;
|
|
101
99
|
};
|
|
102
100
|
}
|
|
@@ -151,6 +151,24 @@ export function mapWorktreeError(stderr, fallbackMessage) {
|
|
|
151
151
|
}
|
|
152
152
|
return new WorktreeError(text.length > 0 ? text : fallbackMessage, "GIT_FAILED");
|
|
153
153
|
}
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
// io — git shell-outs (map stderr → WorktreeError)
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
/**
|
|
158
|
+
* `env` with git hooks off for every git command run with it: core.hooksPath
|
|
159
|
+
* points at /dev/null, through GIT_CONFIG_* (which outrank the repository's
|
|
160
|
+
* own config, a relative hooksPath that a branch carries included).
|
|
161
|
+
*/
|
|
162
|
+
export function gitHooksOff(env) {
|
|
163
|
+
const count = Number.parseInt(env.GIT_CONFIG_COUNT ?? "0", 10);
|
|
164
|
+
const index = Number.isInteger(count) && count >= 0 ? count : 0;
|
|
165
|
+
return {
|
|
166
|
+
...env,
|
|
167
|
+
GIT_CONFIG_COUNT: String(index + 1),
|
|
168
|
+
[`GIT_CONFIG_KEY_${index}`]: "core.hooksPath",
|
|
169
|
+
[`GIT_CONFIG_VALUE_${index}`]: "/dev/null",
|
|
170
|
+
};
|
|
171
|
+
}
|
|
154
172
|
let gitRunner = (repoDir, args) => execFileSync("git", args, {
|
|
155
173
|
cwd: repoDir,
|
|
156
174
|
encoding: "utf-8",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
<key>CFBundlePackageType</key>
|
|
22
22
|
<string>APPL</string>
|
|
23
23
|
<key>CFBundleShortVersionString</key>
|
|
24
|
-
<string>2.9.
|
|
24
|
+
<string>2.9.21</string>
|
|
25
25
|
<key>CFBundleVersion</key>
|
|
26
|
-
<string>2.9.
|
|
26
|
+
<string>2.9.21</string>
|
|
27
27
|
<key>LSMinimumSystemVersion</key>
|
|
28
28
|
<string>11.0</string>
|
|
29
29
|
<key>LSUIElement</key>
|
|
Binary file
|
|
Binary file
|
package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
</data>
|
|
11
11
|
<key>Resources/Assets.car</key>
|
|
12
12
|
<data>
|
|
13
|
-
|
|
13
|
+
EsiTbdQN4UN1DDLvBWMjr8yYs3c=
|
|
14
14
|
</data>
|
|
15
15
|
</dict>
|
|
16
16
|
<key>files2</key>
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
<dict>
|
|
27
27
|
<key>hash2</key>
|
|
28
28
|
<data>
|
|
29
|
-
|
|
29
|
+
xcvTSqFPzlTwYR+iWi6YB+E1VIu0wNx6nZxi4ZTQihY=
|
|
30
30
|
</data>
|
|
31
31
|
</dict>
|
|
32
32
|
</dict>
|
|
@@ -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
|
+
}
|