@h-rig/plugin-inspector-plugin 0.0.6-alpha.186
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/src/cli-parsers.d.ts +7 -0
- package/dist/src/cli-parsers.js +15 -0
- package/dist/src/plugin-command.d.ts +20 -0
- package/dist/src/plugin-command.js +188 -0
- package/dist/src/plugin.d.ts +4 -0
- package/dist/src/plugin.js +241 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @h-rig/plugin-inspector-plugin
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TaskSourceConfig } from "@rig/contracts";
|
|
2
|
+
import type { RigPlugin } from "@rig/core";
|
|
3
|
+
export type CliRigConfig = {
|
|
4
|
+
plugins?: readonly RigPlugin[];
|
|
5
|
+
taskSource?: TaskSourceConfig;
|
|
6
|
+
};
|
|
7
|
+
export declare function loadRigConfigOrNull(projectRoot: string): Promise<CliRigConfig | null>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
3
|
+
|
|
4
|
+
// packages/plugin-inspector-plugin/src/cli-parsers.ts
|
|
5
|
+
async function loadRigConfigOrNull(projectRoot) {
|
|
6
|
+
try {
|
|
7
|
+
const { loadConfig } = await import("@rig/core/load-config");
|
|
8
|
+
return await loadConfig(projectRoot);
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
loadRigConfigOrNull
|
|
15
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RuntimeCliContext } from "@rig/core/config";
|
|
2
|
+
import type { CommandOutcome } from "@rig/contracts";
|
|
3
|
+
export declare function executePlugin(context: RuntimeCliContext, args: string[]): Promise<CommandOutcome>;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a plugin CLI command by exact id ("my-plugin:deploy") or by the
|
|
6
|
+
* unambiguous local part after the namespace colon ("deploy").
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolvePluginCliCommand(commands: readonly {
|
|
9
|
+
id: string;
|
|
10
|
+
family?: string | undefined;
|
|
11
|
+
command?: string | undefined;
|
|
12
|
+
description?: string | undefined;
|
|
13
|
+
aliases?: readonly string[] | undefined;
|
|
14
|
+
}[], requested: string): {
|
|
15
|
+
id: string;
|
|
16
|
+
family?: string | undefined;
|
|
17
|
+
command?: string | undefined;
|
|
18
|
+
description?: string | undefined;
|
|
19
|
+
aliases?: readonly string[] | undefined;
|
|
20
|
+
} | undefined;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
3
|
+
|
|
4
|
+
// packages/plugin-inspector-plugin/src/plugin-command.ts
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import { resolve } from "path";
|
|
7
|
+
import { CliError, requireNoExtraArgs, requireOption, takeOption } from "@rig/std-shared/cli-args";
|
|
8
|
+
import { buildPluginHostContext } from "@rig/core/plugin-host-context";
|
|
9
|
+
|
|
10
|
+
// packages/plugin-inspector-plugin/src/cli-parsers.ts
|
|
11
|
+
async function loadRigConfigOrNull(projectRoot) {
|
|
12
|
+
try {
|
|
13
|
+
const { loadConfig } = await import("@rig/core/load-config");
|
|
14
|
+
return await loadConfig(projectRoot);
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// packages/plugin-inspector-plugin/src/plugin-command.ts
|
|
21
|
+
async function executePlugin(context, args) {
|
|
22
|
+
const [command = "list", ...rest] = args;
|
|
23
|
+
switch (command) {
|
|
24
|
+
case "list": {
|
|
25
|
+
requireNoExtraArgs(rest, "rig plugin list");
|
|
26
|
+
const declarative = [];
|
|
27
|
+
const config = await loadRigConfigOrNull(context.projectRoot);
|
|
28
|
+
if (config && Array.isArray(config.plugins)) {
|
|
29
|
+
for (const plugin of config.plugins) {
|
|
30
|
+
const c = plugin.contributes ?? {};
|
|
31
|
+
declarative.push({
|
|
32
|
+
name: plugin.name,
|
|
33
|
+
version: plugin.version,
|
|
34
|
+
validators: (c.validators ?? []).map((v) => v.id),
|
|
35
|
+
hooks: (c.hooks ?? []).map((h) => h.id),
|
|
36
|
+
agentRoles: (c.agentRoles ?? []).map((r) => r.id),
|
|
37
|
+
repoSources: (c.repoSources ?? []).map((r) => r.id),
|
|
38
|
+
taskSources: (c.taskSources ?? []).map((s) => s.id),
|
|
39
|
+
skills: (c.skills ?? []).map((s) => s.id),
|
|
40
|
+
taskFieldExtensions: (c.taskFieldSchemas ?? []).map((f) => f.id),
|
|
41
|
+
cliCommands: (c.cliCommands ?? []).map((entry) => entry.family ?? entry.id)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (context.outputMode === "text") {
|
|
46
|
+
if (declarative.length === 0) {
|
|
47
|
+
const configExists = ["rig.config.ts", "rig.config.mts", "rig.config.json"].some((name) => existsSync(resolve(context.projectRoot, name)));
|
|
48
|
+
console.log(configExists ? "rig.config found but no plugins could be loaded. If the config imports @rig/* packages, run `bun install` in this project first." : "No plugins loaded. Declare plugins in rig.config.ts.");
|
|
49
|
+
} else {
|
|
50
|
+
console.log("Plugins (rig.config.ts):");
|
|
51
|
+
for (const p of declarative) {
|
|
52
|
+
console.log(` ${p.name}@${p.version}`);
|
|
53
|
+
const lines = [];
|
|
54
|
+
if (p.validators.length)
|
|
55
|
+
lines.push(` validators: ${p.validators.join(", ")}`);
|
|
56
|
+
if (p.hooks.length)
|
|
57
|
+
lines.push(` hooks: ${p.hooks.join(", ")}`);
|
|
58
|
+
if (p.agentRoles.length)
|
|
59
|
+
lines.push(` agent-roles: ${p.agentRoles.join(", ")}`);
|
|
60
|
+
if (p.repoSources.length)
|
|
61
|
+
lines.push(` repo-sources: ${p.repoSources.join(", ")}`);
|
|
62
|
+
if (p.taskSources.length)
|
|
63
|
+
lines.push(` task-sources: ${p.taskSources.join(", ")}`);
|
|
64
|
+
if (p.skills.length)
|
|
65
|
+
lines.push(` skills: ${p.skills.join(", ")}`);
|
|
66
|
+
if (p.taskFieldExtensions.length)
|
|
67
|
+
lines.push(` task-fields: ${p.taskFieldExtensions.join(", ")}`);
|
|
68
|
+
if (p.cliCommands.length)
|
|
69
|
+
lines.push(` cli-families: ${p.cliCommands.join(", ")}`);
|
|
70
|
+
for (const line of lines)
|
|
71
|
+
console.log(line);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
ok: true,
|
|
77
|
+
group: "plugin",
|
|
78
|
+
command,
|
|
79
|
+
details: { declarative }
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
case "validate": {
|
|
83
|
+
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
84
|
+
requireNoExtraArgs(remaining, "rig plugin validate --task <task-id>");
|
|
85
|
+
const taskId = requireOption(task, "--task", "rig plugin validate --task <task-id>");
|
|
86
|
+
const hostCtx = await buildPluginHostContext(context.projectRoot);
|
|
87
|
+
if (!hostCtx) {
|
|
88
|
+
throw new CliError(`No rig.config found at ${context.projectRoot}. Run \`rig init\` to set up plugins.`, 2);
|
|
89
|
+
}
|
|
90
|
+
const validators = hostCtx.validatorRegistry.list();
|
|
91
|
+
const results = [];
|
|
92
|
+
for (const validator of validators) {
|
|
93
|
+
try {
|
|
94
|
+
results.push(await validator.run({
|
|
95
|
+
taskId,
|
|
96
|
+
workspaceRoot: context.projectRoot,
|
|
97
|
+
scope: []
|
|
98
|
+
}));
|
|
99
|
+
} catch (error) {
|
|
100
|
+
results.push({
|
|
101
|
+
id: validator.id,
|
|
102
|
+
passed: false,
|
|
103
|
+
summary: `${validator.id} failed unexpectedly`,
|
|
104
|
+
details: `${error}`
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const passed = results.filter((result) => result.passed).length;
|
|
109
|
+
const failed = results.length - passed;
|
|
110
|
+
if (context.outputMode === "text") {
|
|
111
|
+
if (results.length === 0) {
|
|
112
|
+
console.log("No plugin validators registered.");
|
|
113
|
+
} else {
|
|
114
|
+
for (const result of results) {
|
|
115
|
+
const icon = result.passed ? "PASS" : "FAIL";
|
|
116
|
+
console.log(`[${icon}] ${result.id}: ${result.summary}`);
|
|
117
|
+
if (result.details && !result.passed) {
|
|
118
|
+
console.log(result.details);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (failed > 0) {
|
|
124
|
+
throw new CliError(`Plugin validation failed for ${failed} validator(s).`, 2, { hint: "Fix the reported validators, then re-run `rig plugin validate --task <id>`." });
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
ok: true,
|
|
128
|
+
group: "plugin",
|
|
129
|
+
command,
|
|
130
|
+
details: {
|
|
131
|
+
taskId,
|
|
132
|
+
passed,
|
|
133
|
+
failed,
|
|
134
|
+
results
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
case "run": {
|
|
139
|
+
const [commandId, ...commandArgs] = rest;
|
|
140
|
+
if (!commandId) {
|
|
141
|
+
throw new CliError("Usage: rig plugin run <command-id> [args...]", 1, { hint: "Run `rig plugin list` to see plugin-contributed command ids." });
|
|
142
|
+
}
|
|
143
|
+
const hostCtx = await buildPluginHostContext(context.projectRoot);
|
|
144
|
+
if (!hostCtx) {
|
|
145
|
+
throw new CliError(`No rig.config found at ${context.projectRoot}. Run \`rig init\` to set up plugins.`, 2);
|
|
146
|
+
}
|
|
147
|
+
const registration = resolvePluginCliCommand(hostCtx.pluginHost.listCliCommands(), commandId);
|
|
148
|
+
if (!registration) {
|
|
149
|
+
const available = hostCtx.pluginHost.listCliCommands().map((entry) => entry.id);
|
|
150
|
+
throw new CliError(available.length > 0 ? `Unknown plugin command "${commandId}". Available: ${available.join(", ")}` : `No plugin CLI commands are registered. Plugins contribute them via contributes.cliCommands.`, 2);
|
|
151
|
+
}
|
|
152
|
+
if (!registration.command) {
|
|
153
|
+
throw new CliError(`Plugin CLI family "${registration.id}" is an in-process command; invoke it as \`rig ${registration.family ?? registration.id}\`, not through \`rig plugin run\`.`, 1);
|
|
154
|
+
}
|
|
155
|
+
if (context.dryRun) {
|
|
156
|
+
if (context.outputMode === "text") {
|
|
157
|
+
console.log(`[dry-run] ${registration.command}${commandArgs.length ? ` ${commandArgs.join(" ")}` : ""}`);
|
|
158
|
+
}
|
|
159
|
+
return { ok: true, group: "plugin", command, details: { id: registration.id, dryRun: true } };
|
|
160
|
+
}
|
|
161
|
+
const proc = Bun.spawn(["bash", "-c", `${registration.command} "$@"`, registration.id, ...commandArgs], {
|
|
162
|
+
cwd: context.projectRoot,
|
|
163
|
+
env: process.env,
|
|
164
|
+
stdin: "inherit",
|
|
165
|
+
stdout: "inherit",
|
|
166
|
+
stderr: "inherit"
|
|
167
|
+
});
|
|
168
|
+
const exitCode = await proc.exited;
|
|
169
|
+
if (exitCode !== 0) {
|
|
170
|
+
throw new CliError(`Plugin command "${registration.id}" exited with code ${exitCode}.`, exitCode, { hint: "Run `rig plugin list` to inspect the contributing plugin, or re-run with --json for details." });
|
|
171
|
+
}
|
|
172
|
+
return { ok: true, group: "plugin", command, details: { id: registration.id, exitCode } };
|
|
173
|
+
}
|
|
174
|
+
default:
|
|
175
|
+
throw new CliError(`Unknown plugin command: ${command}`, 1, { hint: "Run `rig plugin --help` \u2014 commands are list|validate|run." });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function resolvePluginCliCommand(commands, requested) {
|
|
179
|
+
const exact = commands.find((entry) => entry.id === requested || entry.family === requested || (entry.aliases ?? []).includes(requested));
|
|
180
|
+
if (exact)
|
|
181
|
+
return exact;
|
|
182
|
+
const byLocalPart = commands.filter((entry) => entry.id.split(":").slice(1).join(":") === requested);
|
|
183
|
+
return byLocalPart.length === 1 ? byLocalPart[0] : undefined;
|
|
184
|
+
}
|
|
185
|
+
export {
|
|
186
|
+
resolvePluginCliCommand,
|
|
187
|
+
executePlugin
|
|
188
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const PLUGIN_INSPECTOR_PLUGIN_NAME = "@rig/plugin-inspector-plugin";
|
|
2
|
+
export declare const pluginInspectorPlugin: import("@rig/core").RigPlugin;
|
|
3
|
+
export declare function createPluginInspectorPlugin(): import("@rig/core").RigPlugin;
|
|
4
|
+
export default pluginInspectorPlugin;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
|
+
var __require = import.meta.require;
|
|
18
|
+
|
|
19
|
+
// packages/plugin-inspector-plugin/src/cli-parsers.ts
|
|
20
|
+
async function loadRigConfigOrNull(projectRoot) {
|
|
21
|
+
try {
|
|
22
|
+
const { loadConfig } = await import("@rig/core/load-config");
|
|
23
|
+
return await loadConfig(projectRoot);
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// packages/plugin-inspector-plugin/src/plugin-command.ts
|
|
30
|
+
var exports_plugin_command = {};
|
|
31
|
+
__export(exports_plugin_command, {
|
|
32
|
+
resolvePluginCliCommand: () => resolvePluginCliCommand,
|
|
33
|
+
executePlugin: () => executePlugin
|
|
34
|
+
});
|
|
35
|
+
import { existsSync } from "fs";
|
|
36
|
+
import { resolve } from "path";
|
|
37
|
+
import { CliError, requireNoExtraArgs, requireOption, takeOption } from "@rig/std-shared/cli-args";
|
|
38
|
+
import { buildPluginHostContext } from "@rig/core/plugin-host-context";
|
|
39
|
+
async function executePlugin(context, args) {
|
|
40
|
+
const [command = "list", ...rest] = args;
|
|
41
|
+
switch (command) {
|
|
42
|
+
case "list": {
|
|
43
|
+
requireNoExtraArgs(rest, "rig plugin list");
|
|
44
|
+
const declarative = [];
|
|
45
|
+
const config = await loadRigConfigOrNull(context.projectRoot);
|
|
46
|
+
if (config && Array.isArray(config.plugins)) {
|
|
47
|
+
for (const plugin of config.plugins) {
|
|
48
|
+
const c = plugin.contributes ?? {};
|
|
49
|
+
declarative.push({
|
|
50
|
+
name: plugin.name,
|
|
51
|
+
version: plugin.version,
|
|
52
|
+
validators: (c.validators ?? []).map((v) => v.id),
|
|
53
|
+
hooks: (c.hooks ?? []).map((h) => h.id),
|
|
54
|
+
agentRoles: (c.agentRoles ?? []).map((r) => r.id),
|
|
55
|
+
repoSources: (c.repoSources ?? []).map((r) => r.id),
|
|
56
|
+
taskSources: (c.taskSources ?? []).map((s) => s.id),
|
|
57
|
+
skills: (c.skills ?? []).map((s) => s.id),
|
|
58
|
+
taskFieldExtensions: (c.taskFieldSchemas ?? []).map((f) => f.id),
|
|
59
|
+
cliCommands: (c.cliCommands ?? []).map((entry) => entry.family ?? entry.id)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (context.outputMode === "text") {
|
|
64
|
+
if (declarative.length === 0) {
|
|
65
|
+
const configExists = ["rig.config.ts", "rig.config.mts", "rig.config.json"].some((name) => existsSync(resolve(context.projectRoot, name)));
|
|
66
|
+
console.log(configExists ? "rig.config found but no plugins could be loaded. If the config imports @rig/* packages, run `bun install` in this project first." : "No plugins loaded. Declare plugins in rig.config.ts.");
|
|
67
|
+
} else {
|
|
68
|
+
console.log("Plugins (rig.config.ts):");
|
|
69
|
+
for (const p of declarative) {
|
|
70
|
+
console.log(` ${p.name}@${p.version}`);
|
|
71
|
+
const lines = [];
|
|
72
|
+
if (p.validators.length)
|
|
73
|
+
lines.push(` validators: ${p.validators.join(", ")}`);
|
|
74
|
+
if (p.hooks.length)
|
|
75
|
+
lines.push(` hooks: ${p.hooks.join(", ")}`);
|
|
76
|
+
if (p.agentRoles.length)
|
|
77
|
+
lines.push(` agent-roles: ${p.agentRoles.join(", ")}`);
|
|
78
|
+
if (p.repoSources.length)
|
|
79
|
+
lines.push(` repo-sources: ${p.repoSources.join(", ")}`);
|
|
80
|
+
if (p.taskSources.length)
|
|
81
|
+
lines.push(` task-sources: ${p.taskSources.join(", ")}`);
|
|
82
|
+
if (p.skills.length)
|
|
83
|
+
lines.push(` skills: ${p.skills.join(", ")}`);
|
|
84
|
+
if (p.taskFieldExtensions.length)
|
|
85
|
+
lines.push(` task-fields: ${p.taskFieldExtensions.join(", ")}`);
|
|
86
|
+
if (p.cliCommands.length)
|
|
87
|
+
lines.push(` cli-families: ${p.cliCommands.join(", ")}`);
|
|
88
|
+
for (const line of lines)
|
|
89
|
+
console.log(line);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
ok: true,
|
|
95
|
+
group: "plugin",
|
|
96
|
+
command,
|
|
97
|
+
details: { declarative }
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
case "validate": {
|
|
101
|
+
const { value: task, rest: remaining } = takeOption(rest, "--task");
|
|
102
|
+
requireNoExtraArgs(remaining, "rig plugin validate --task <task-id>");
|
|
103
|
+
const taskId = requireOption(task, "--task", "rig plugin validate --task <task-id>");
|
|
104
|
+
const hostCtx = await buildPluginHostContext(context.projectRoot);
|
|
105
|
+
if (!hostCtx) {
|
|
106
|
+
throw new CliError(`No rig.config found at ${context.projectRoot}. Run \`rig init\` to set up plugins.`, 2);
|
|
107
|
+
}
|
|
108
|
+
const validators = hostCtx.validatorRegistry.list();
|
|
109
|
+
const results = [];
|
|
110
|
+
for (const validator of validators) {
|
|
111
|
+
try {
|
|
112
|
+
results.push(await validator.run({
|
|
113
|
+
taskId,
|
|
114
|
+
workspaceRoot: context.projectRoot,
|
|
115
|
+
scope: []
|
|
116
|
+
}));
|
|
117
|
+
} catch (error) {
|
|
118
|
+
results.push({
|
|
119
|
+
id: validator.id,
|
|
120
|
+
passed: false,
|
|
121
|
+
summary: `${validator.id} failed unexpectedly`,
|
|
122
|
+
details: `${error}`
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const passed = results.filter((result) => result.passed).length;
|
|
127
|
+
const failed = results.length - passed;
|
|
128
|
+
if (context.outputMode === "text") {
|
|
129
|
+
if (results.length === 0) {
|
|
130
|
+
console.log("No plugin validators registered.");
|
|
131
|
+
} else {
|
|
132
|
+
for (const result of results) {
|
|
133
|
+
const icon = result.passed ? "PASS" : "FAIL";
|
|
134
|
+
console.log(`[${icon}] ${result.id}: ${result.summary}`);
|
|
135
|
+
if (result.details && !result.passed) {
|
|
136
|
+
console.log(result.details);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (failed > 0) {
|
|
142
|
+
throw new CliError(`Plugin validation failed for ${failed} validator(s).`, 2, { hint: "Fix the reported validators, then re-run `rig plugin validate --task <id>`." });
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
ok: true,
|
|
146
|
+
group: "plugin",
|
|
147
|
+
command,
|
|
148
|
+
details: {
|
|
149
|
+
taskId,
|
|
150
|
+
passed,
|
|
151
|
+
failed,
|
|
152
|
+
results
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
case "run": {
|
|
157
|
+
const [commandId, ...commandArgs] = rest;
|
|
158
|
+
if (!commandId) {
|
|
159
|
+
throw new CliError("Usage: rig plugin run <command-id> [args...]", 1, { hint: "Run `rig plugin list` to see plugin-contributed command ids." });
|
|
160
|
+
}
|
|
161
|
+
const hostCtx = await buildPluginHostContext(context.projectRoot);
|
|
162
|
+
if (!hostCtx) {
|
|
163
|
+
throw new CliError(`No rig.config found at ${context.projectRoot}. Run \`rig init\` to set up plugins.`, 2);
|
|
164
|
+
}
|
|
165
|
+
const registration = resolvePluginCliCommand(hostCtx.pluginHost.listCliCommands(), commandId);
|
|
166
|
+
if (!registration) {
|
|
167
|
+
const available = hostCtx.pluginHost.listCliCommands().map((entry) => entry.id);
|
|
168
|
+
throw new CliError(available.length > 0 ? `Unknown plugin command "${commandId}". Available: ${available.join(", ")}` : `No plugin CLI commands are registered. Plugins contribute them via contributes.cliCommands.`, 2);
|
|
169
|
+
}
|
|
170
|
+
if (!registration.command) {
|
|
171
|
+
throw new CliError(`Plugin CLI family "${registration.id}" is an in-process command; invoke it as \`rig ${registration.family ?? registration.id}\`, not through \`rig plugin run\`.`, 1);
|
|
172
|
+
}
|
|
173
|
+
if (context.dryRun) {
|
|
174
|
+
if (context.outputMode === "text") {
|
|
175
|
+
console.log(`[dry-run] ${registration.command}${commandArgs.length ? ` ${commandArgs.join(" ")}` : ""}`);
|
|
176
|
+
}
|
|
177
|
+
return { ok: true, group: "plugin", command, details: { id: registration.id, dryRun: true } };
|
|
178
|
+
}
|
|
179
|
+
const proc = Bun.spawn(["bash", "-c", `${registration.command} "$@"`, registration.id, ...commandArgs], {
|
|
180
|
+
cwd: context.projectRoot,
|
|
181
|
+
env: process.env,
|
|
182
|
+
stdin: "inherit",
|
|
183
|
+
stdout: "inherit",
|
|
184
|
+
stderr: "inherit"
|
|
185
|
+
});
|
|
186
|
+
const exitCode = await proc.exited;
|
|
187
|
+
if (exitCode !== 0) {
|
|
188
|
+
throw new CliError(`Plugin command "${registration.id}" exited with code ${exitCode}.`, exitCode, { hint: "Run `rig plugin list` to inspect the contributing plugin, or re-run with --json for details." });
|
|
189
|
+
}
|
|
190
|
+
return { ok: true, group: "plugin", command, details: { id: registration.id, exitCode } };
|
|
191
|
+
}
|
|
192
|
+
default:
|
|
193
|
+
throw new CliError(`Unknown plugin command: ${command}`, 1, { hint: "Run `rig plugin --help` \u2014 commands are list|validate|run." });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function resolvePluginCliCommand(commands, requested) {
|
|
197
|
+
const exact = commands.find((entry) => entry.id === requested || entry.family === requested || (entry.aliases ?? []).includes(requested));
|
|
198
|
+
if (exact)
|
|
199
|
+
return exact;
|
|
200
|
+
const byLocalPart = commands.filter((entry) => entry.id.split(":").slice(1).join(":") === requested);
|
|
201
|
+
return byLocalPart.length === 1 ? byLocalPart[0] : undefined;
|
|
202
|
+
}
|
|
203
|
+
var init_plugin_command = () => {};
|
|
204
|
+
|
|
205
|
+
// packages/plugin-inspector-plugin/src/plugin.ts
|
|
206
|
+
import { definePlugin } from "@rig/core/config";
|
|
207
|
+
var PLUGIN_INSPECTOR_PLUGIN_NAME = "@rig/plugin-inspector-plugin";
|
|
208
|
+
var pluginCommand = {
|
|
209
|
+
id: `${PLUGIN_INSPECTOR_PLUGIN_NAME}:plugin`,
|
|
210
|
+
family: "plugin",
|
|
211
|
+
description: "Inspect and run plugin compatibility commands.",
|
|
212
|
+
projectRequired: false,
|
|
213
|
+
run: async (context, args) => (await Promise.resolve().then(() => (init_plugin_command(), exports_plugin_command))).executePlugin(context, [...args]),
|
|
214
|
+
helpDoc: {
|
|
215
|
+
name: "plugin",
|
|
216
|
+
summary: "Plugin listing, validation, and plugin-contributed commands.",
|
|
217
|
+
usage: ["rig plugin <list|validate|run> [options]"],
|
|
218
|
+
commands: [
|
|
219
|
+
{ command: "list", description: "List plugins declared in rig.config.ts and their contributions.", primary: true },
|
|
220
|
+
{ command: "validate --task <id>", description: "Run plugin-contributed validators for a task.", primary: true },
|
|
221
|
+
{ command: "run <command-id> [args...]", description: "Execute a plugin-contributed CLI command (also callable as `rig <command-id>`)." }
|
|
222
|
+
],
|
|
223
|
+
examples: ["rig plugin list", "rig plugin run <command-id>"]
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
var pluginInspectorPlugin = definePlugin({
|
|
227
|
+
name: PLUGIN_INSPECTOR_PLUGIN_NAME,
|
|
228
|
+
version: "0.0.0-alpha.1",
|
|
229
|
+
effects: { readsFiles: true, contributesCliCommands: true },
|
|
230
|
+
contributes: { cliCommands: [pluginCommand] }
|
|
231
|
+
});
|
|
232
|
+
function createPluginInspectorPlugin() {
|
|
233
|
+
return pluginInspectorPlugin;
|
|
234
|
+
}
|
|
235
|
+
var plugin_default = pluginInspectorPlugin;
|
|
236
|
+
export {
|
|
237
|
+
pluginInspectorPlugin,
|
|
238
|
+
plugin_default as default,
|
|
239
|
+
createPluginInspectorPlugin,
|
|
240
|
+
PLUGIN_INSPECTOR_PLUGIN_NAME
|
|
241
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@h-rig/plugin-inspector-plugin",
|
|
3
|
+
"version": "0.0.6-alpha.186",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "First-party Rig plugin-introspection command plugin (rig plugin list/...).",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/src/plugin.d.ts",
|
|
14
|
+
"import": "./dist/src/plugin.js"
|
|
15
|
+
},
|
|
16
|
+
"./plugin": {
|
|
17
|
+
"types": "./dist/src/plugin.d.ts",
|
|
18
|
+
"import": "./dist/src/plugin.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"bun": ">=1.3.11"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.186",
|
|
26
|
+
"@rig/core": "npm:@h-rig/core@0.0.6-alpha.186",
|
|
27
|
+
"@rig/std-shared": "npm:@h-rig/std-shared@0.0.6-alpha.186"
|
|
28
|
+
}
|
|
29
|
+
}
|