@h-rig/cli-surface-plugin 0.0.6-alpha.146

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 (94) hide show
  1. package/README.md +1 -0
  2. package/dist/src/app/drone-ui.d.ts +34 -0
  3. package/dist/src/app/drone-ui.js +278 -0
  4. package/dist/src/commands/_async-ui.d.ts +10 -0
  5. package/dist/src/commands/_async-ui.js +121 -0
  6. package/dist/src/commands/_cli-format.d.ts +56 -0
  7. package/dist/src/commands/_cli-format.js +332 -0
  8. package/dist/src/commands/_connection-state.d.ts +54 -0
  9. package/dist/src/commands/_connection-state.js +187 -0
  10. package/dist/src/commands/_doctor-checks.d.ts +9 -0
  11. package/dist/src/commands/_doctor-checks.js +24 -0
  12. package/dist/src/commands/_help-catalog.d.ts +29 -0
  13. package/dist/src/commands/_help-catalog.js +157 -0
  14. package/dist/src/commands/_inprocess-services.d.ts +33 -0
  15. package/dist/src/commands/_inprocess-services.js +102 -0
  16. package/dist/src/commands/_json-output.d.ts +11 -0
  17. package/dist/src/commands/_json-output.js +54 -0
  18. package/dist/src/commands/_parsers.d.ts +15 -0
  19. package/dist/src/commands/_parsers.js +114 -0
  20. package/dist/src/commands/_paths.d.ts +11 -0
  21. package/dist/src/commands/_paths.js +50 -0
  22. package/dist/src/commands/_pi-frontend.d.ts +35 -0
  23. package/dist/src/commands/_pi-frontend.js +64 -0
  24. package/dist/src/commands/_pi-install.d.ts +42 -0
  25. package/dist/src/commands/_pi-install.js +167 -0
  26. package/dist/src/commands/_policy.d.ts +8 -0
  27. package/dist/src/commands/_policy.js +138 -0
  28. package/dist/src/commands/_probes.d.ts +1 -0
  29. package/dist/src/commands/_probes.js +13 -0
  30. package/dist/src/commands/_run-driver-helpers.d.ts +26 -0
  31. package/dist/src/commands/_run-driver-helpers.js +132 -0
  32. package/dist/src/commands/_run-subcommands.d.ts +3 -0
  33. package/dist/src/commands/_run-subcommands.js +31 -0
  34. package/dist/src/commands/_spinner.d.ts +25 -0
  35. package/dist/src/commands/_spinner.js +65 -0
  36. package/dist/src/commands/agent.d.ts +3 -0
  37. package/dist/src/commands/agent.js +322 -0
  38. package/dist/src/commands/config.d.ts +3 -0
  39. package/dist/src/commands/config.js +193 -0
  40. package/dist/src/commands/dist.d.ts +28 -0
  41. package/dist/src/commands/dist.js +435 -0
  42. package/dist/src/commands/doctor.d.ts +3 -0
  43. package/dist/src/commands/doctor.js +171 -0
  44. package/dist/src/commands/github.d.ts +3 -0
  45. package/dist/src/commands/github.js +342 -0
  46. package/dist/src/commands/inbox.d.ts +19 -0
  47. package/dist/src/commands/inbox.js +241 -0
  48. package/dist/src/commands/init.d.ts +64 -0
  49. package/dist/src/commands/init.js +1449 -0
  50. package/dist/src/commands/inspect.d.ts +20 -0
  51. package/dist/src/commands/inspect.js +337 -0
  52. package/dist/src/commands/pi.d.ts +3 -0
  53. package/dist/src/commands/pi.js +177 -0
  54. package/dist/src/commands/plugin.d.ts +20 -0
  55. package/dist/src/commands/plugin.js +238 -0
  56. package/dist/src/commands/profile-and-review.d.ts +4 -0
  57. package/dist/src/commands/profile-and-review.js +223 -0
  58. package/dist/src/commands/queue.d.ts +3 -0
  59. package/dist/src/commands/queue.js +197 -0
  60. package/dist/src/commands/remote.d.ts +3 -0
  61. package/dist/src/commands/remote.js +516 -0
  62. package/dist/src/commands/repo-git-harness.d.ts +5 -0
  63. package/dist/src/commands/repo-git-harness.js +282 -0
  64. package/dist/src/commands/run.d.ts +22 -0
  65. package/dist/src/commands/run.js +645 -0
  66. package/dist/src/commands/server.d.ts +3 -0
  67. package/dist/src/commands/server.js +155 -0
  68. package/dist/src/commands/setup.d.ts +16 -0
  69. package/dist/src/commands/setup.js +356 -0
  70. package/dist/src/commands/stats.d.ts +11 -0
  71. package/dist/src/commands/stats.js +219 -0
  72. package/dist/src/commands/task-run-driver.d.ts +93 -0
  73. package/dist/src/commands/task-run-driver.js +136 -0
  74. package/dist/src/commands/task.d.ts +46 -0
  75. package/dist/src/commands/task.js +555 -0
  76. package/dist/src/commands/test.d.ts +3 -0
  77. package/dist/src/commands/test.js +46 -0
  78. package/dist/src/commands/triage.d.ts +11 -0
  79. package/dist/src/commands/triage.js +224 -0
  80. package/dist/src/commands/workspace.d.ts +3 -0
  81. package/dist/src/commands/workspace.js +130 -0
  82. package/dist/src/kernel-dispatch.d.ts +15 -0
  83. package/dist/src/kernel-dispatch.js +16 -0
  84. package/dist/src/plugin.d.ts +3 -0
  85. package/dist/src/plugin.js +5440 -0
  86. package/dist/src/rig-config-package-deps.d.ts +10 -0
  87. package/dist/src/rig-config-package-deps.js +272 -0
  88. package/dist/src/runner.d.ts +47 -0
  89. package/dist/src/runner.js +267 -0
  90. package/dist/src/version.d.ts +8 -0
  91. package/dist/src/version.js +47 -0
  92. package/dist/src/withMutedConsole.d.ts +2 -0
  93. package/dist/src/withMutedConsole.js +42 -0
  94. package/package.json +34 -0
@@ -0,0 +1,282 @@
1
+ // @bun
2
+ // packages/cli-surface-plugin/src/runner.ts
3
+ import { EventBus } from "@rig/runtime/control-plane/runtime/events";
4
+ import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
5
+ import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
6
+ import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
7
+
8
+ class CliError extends RuntimeCliError {
9
+ hint;
10
+ constructor(message, exitCode = 1, options = {}) {
11
+ super(message, exitCode);
12
+ if (options.hint?.trim()) {
13
+ this.hint = options.hint.trim();
14
+ }
15
+ }
16
+ }
17
+ function formatCommand(parts) {
18
+ return parts.map((part) => /[^a-zA-Z0-9_./:-]/.test(part) ? JSON.stringify(part) : part).join(" ");
19
+ }
20
+ function takeFlag(args, flag) {
21
+ const rest = [];
22
+ let value = false;
23
+ for (const arg of args) {
24
+ if (arg === flag) {
25
+ value = true;
26
+ continue;
27
+ }
28
+ rest.push(arg);
29
+ }
30
+ return { value, rest };
31
+ }
32
+ function takeOption(args, option) {
33
+ const rest = [];
34
+ let value;
35
+ for (let index = 0;index < args.length; index += 1) {
36
+ const current = args[index];
37
+ if (current === option) {
38
+ const next = args[index + 1];
39
+ if (!next || next.startsWith("-")) {
40
+ throw new CliError(`Missing value for ${option}`, 1, { hint: `Provide a value after ${option}, e.g. \`${option} <value>\`.` });
41
+ }
42
+ value = next;
43
+ index += 1;
44
+ continue;
45
+ }
46
+ if (current !== undefined) {
47
+ rest.push(current);
48
+ }
49
+ }
50
+ return { value, rest };
51
+ }
52
+ function requireNoExtraArgs(args, usage) {
53
+ if (args.length > 0) {
54
+ throw new CliError(`Unexpected arguments: ${args.join(" ")}
55
+ Usage: ${usage}`);
56
+ }
57
+ }
58
+
59
+ // packages/cli-surface-plugin/src/commands/repo-git-harness.ts
60
+ import { executeHarnessCommand } from "@rig/runtime/control-plane/native/harness-cli";
61
+ import { repoEnsure, resetBaseline } from "@rig/runtime/control-plane/native/repo-ops";
62
+
63
+ // packages/cli-surface-plugin/src/withMutedConsole.ts
64
+ function isPromise(value) {
65
+ if (typeof value !== "object" && typeof value !== "function") {
66
+ return false;
67
+ }
68
+ return value !== null && typeof value.then === "function";
69
+ }
70
+ function withMutedConsole(mute, fn) {
71
+ if (!mute) {
72
+ return fn();
73
+ }
74
+ const originalLog = console.log;
75
+ const originalWarn = console.warn;
76
+ const originalInfo = console.info;
77
+ const restore = () => {
78
+ console.log = originalLog;
79
+ console.warn = originalWarn;
80
+ console.info = originalInfo;
81
+ };
82
+ console.log = () => {};
83
+ console.warn = () => {};
84
+ console.info = () => {};
85
+ try {
86
+ const result = fn();
87
+ if (isPromise(result)) {
88
+ return result.finally(restore);
89
+ }
90
+ restore();
91
+ return result;
92
+ } catch (error) {
93
+ restore();
94
+ throw error;
95
+ } finally {
96
+ if (console.log === originalLog) {
97
+ restore();
98
+ }
99
+ }
100
+ }
101
+
102
+ // packages/cli-surface-plugin/src/commands/_policy.ts
103
+ import { appendFileSync, existsSync, mkdirSync, readFileSync } from "fs";
104
+ import { resolve as resolve2 } from "path";
105
+
106
+ // packages/cli-surface-plugin/src/commands/_paths.ts
107
+ import { resolve } from "path";
108
+ import { resolveMonorepoRoot } from "@rig/runtime/layout";
109
+ function resolveControlPlaneHostStateRoot(projectRoot) {
110
+ return resolve(projectRoot, ".rig");
111
+ }
112
+ function resolveControlPlaneHostLogsDir(projectRoot) {
113
+ return resolve(resolveControlPlaneHostStateRoot(projectRoot), "logs");
114
+ }
115
+ function resolveControlPlaneDefinitionRoot(projectRoot) {
116
+ return resolve(projectRoot, "rig");
117
+ }
118
+
119
+ // packages/cli-surface-plugin/src/commands/_policy.ts
120
+ function loadPolicyFile(projectRoot) {
121
+ const policyPath = resolve2(resolveControlPlaneDefinitionRoot(projectRoot), "policy", "policy.json");
122
+ if (!existsSync(policyPath)) {
123
+ return { mode: "observe", rules: [] };
124
+ }
125
+ try {
126
+ const parsed = JSON.parse(readFileSync(policyPath, "utf8"));
127
+ const mode = parsed.mode === "off" || parsed.mode === "observe" || parsed.mode === "enforce" ? parsed.mode : "observe";
128
+ const rules = Array.isArray(parsed.rules) ? parsed.rules.filter((value) => Boolean(value && typeof value === "object" && !Array.isArray(value))).map((value, index) => {
129
+ const rule = {
130
+ id: typeof value.id === "string" && value.id.trim() ? value.id.trim() : `rule-${index + 1}`
131
+ };
132
+ const reason = typeof value.reason === "string" && value.reason.trim() ? value.reason.trim() : null;
133
+ const match = typeof value.match === "string" && value.match.trim() ? value.match.trim() : null;
134
+ const command = typeof value.command === "string" && value.command.trim() ? value.command.trim() : null;
135
+ if (reason)
136
+ return { ...rule, reason };
137
+ if (match && command)
138
+ return { ...rule, match, command };
139
+ if (match)
140
+ return { ...rule, match };
141
+ if (command)
142
+ return { ...rule, command };
143
+ return rule;
144
+ }) : [];
145
+ return { mode, rules };
146
+ } catch {
147
+ return { mode: "observe", rules: [] };
148
+ }
149
+ }
150
+ function matchingRules(command, rules) {
151
+ return rules.filter((rule) => {
152
+ const rawPattern = rule.command ?? rule.match;
153
+ if (!rawPattern)
154
+ return false;
155
+ try {
156
+ return new RegExp(rawPattern, "i").test(command);
157
+ } catch {
158
+ return command.includes(rawPattern);
159
+ }
160
+ });
161
+ }
162
+ function resolveEffectivePolicyMode(context) {
163
+ const envMode = process.env.RIG_BASH_MODE;
164
+ if (envMode === "off" || envMode === "observe" || envMode === "enforce") {
165
+ return envMode;
166
+ }
167
+ return context.policyMode ?? loadPolicyFile(context.projectRoot).mode;
168
+ }
169
+ function appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action) {
170
+ if (mode === "off") {
171
+ return;
172
+ }
173
+ const logsDir = resolveControlPlaneHostLogsDir(context.projectRoot);
174
+ const logFile = resolve2(logsDir, "controlled-bash.jsonl");
175
+ mkdirSync(logsDir, { recursive: true });
176
+ const payload = {
177
+ timestamp: new Date().toISOString(),
178
+ mode,
179
+ cwd: process.cwd(),
180
+ pid: process.pid,
181
+ ppid: process.ppid,
182
+ argv: args,
183
+ command,
184
+ matchedRuleIds
185
+ };
186
+ if (action) {
187
+ payload.action = action;
188
+ }
189
+ appendFileSync(logFile, `${JSON.stringify(payload)}
190
+ `, "utf-8");
191
+ }
192
+ async function enforceNativeCommandPolicy(context, args, options) {
193
+ const mode = resolveEffectivePolicyMode(context);
194
+ const command = formatCommand([options.commandPrefix, ...args]);
195
+ const rules = matchingRules(command, loadPolicyFile(context.projectRoot).rules);
196
+ const matchedRuleIds = rules.map((rule) => rule.id);
197
+ const action = rules.length === 0 ? "allow" : mode === "enforce" ? "block" : "warn";
198
+ await context.emitEvent("policy.decision", {
199
+ target: "command",
200
+ command,
201
+ mode,
202
+ allowed: action !== "block",
203
+ matchedRuleIds,
204
+ reasons: rules.map((rule) => rule.reason).filter(Boolean)
205
+ });
206
+ if (options.writeAuditLog) {
207
+ appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action === "block" ? "blocked" : action === "warn" ? "warn" : undefined);
208
+ }
209
+ if (action === "block") {
210
+ throw new CliError(`Policy blocked command: ${command}`, 126, {
211
+ hint: "Review rig/policy/policy.json, or re-run with `--policy-mode observe` to log instead of block."
212
+ });
213
+ }
214
+ }
215
+
216
+ // packages/cli-surface-plugin/src/commands/repo-git-harness.ts
217
+ async function executeRepo(context, args) {
218
+ const [command = "sync", ...rest] = args;
219
+ switch (command) {
220
+ case "sync": {
221
+ const { value: task, rest: remaining } = takeOption(rest, "--task");
222
+ requireNoExtraArgs(remaining, "rig repo sync [--task <task-id>]");
223
+ withMutedConsole(context.outputMode === "json", () => repoEnsure(context.projectRoot, task || undefined));
224
+ return { ok: true, group: "repo", command, details: { task: task || null } };
225
+ }
226
+ case "reset-baseline": {
227
+ const { value: keepTaskStatusFlag, rest: remaining } = takeFlag(rest, "--keep-task-status");
228
+ requireNoExtraArgs(remaining, "rig repo reset-baseline [--keep-task-status]");
229
+ withMutedConsole(context.outputMode === "json", () => resetBaseline(context.projectRoot, keepTaskStatusFlag));
230
+ return { ok: true, group: "repo", command, details: { keepTaskStatus: keepTaskStatusFlag } };
231
+ }
232
+ default:
233
+ throw new CliError(`Unknown repo command: ${command}`, 1, { hint: "Run `rig repo --help` \u2014 commands are sync|reset-baseline." });
234
+ }
235
+ }
236
+ async function executeGit(context, args) {
237
+ if (args.length === 0) {
238
+ throw new CliError("Usage: rig git <git-flow args...>");
239
+ }
240
+ await enforceNativeCommandPolicy(context, args, {
241
+ commandPrefix: "rig-agent git",
242
+ writeAuditLog: false
243
+ });
244
+ if (context.dryRun) {
245
+ if (context.outputMode === "text") {
246
+ console.log(`[dry-run] rig git ${args.join(" ")}`);
247
+ }
248
+ return { ok: true, group: "git", command: args[0] ?? "git" };
249
+ }
250
+ try {
251
+ await executeHarnessCommand(context.projectRoot, ["git", ...args]);
252
+ } catch (error) {
253
+ throw new CliError(error instanceof Error ? error.message : String(error), 2);
254
+ }
255
+ return { ok: true, group: "git", command: args[0] ?? "git" };
256
+ }
257
+ async function executeHarness(context, args) {
258
+ if (args.length === 0) {
259
+ throw new CliError("Usage: rig harness <harness args...>");
260
+ }
261
+ await enforceNativeCommandPolicy(context, args, {
262
+ commandPrefix: "rig-agent",
263
+ writeAuditLog: true
264
+ });
265
+ if (context.dryRun) {
266
+ if (context.outputMode === "text") {
267
+ console.log(`[dry-run] rig harness ${args.join(" ")}`);
268
+ }
269
+ return { ok: true, group: "harness", command: args[0] ?? "harness" };
270
+ }
271
+ try {
272
+ await executeHarnessCommand(context.projectRoot, args);
273
+ } catch (error) {
274
+ throw new CliError(error instanceof Error ? error.message : String(error), 2);
275
+ }
276
+ return { ok: true, group: "harness", command: args[0] ?? "harness" };
277
+ }
278
+ export {
279
+ executeRepo,
280
+ executeHarness,
281
+ executeGit
282
+ };
@@ -0,0 +1,22 @@
1
+ import type { CommandOutcome } from "@rig/runtime";
2
+ import type { RunControl, RunJoinTarget, RunRecord, TaskLike } from "@rig/client";
3
+ import { type RunnerContext } from "../runner";
4
+ export type RunTaskLike = TaskLike & Record<string, unknown>;
5
+ export interface RunExecutorDeps {
6
+ readonly listRuns?: (projectRoot: string) => Promise<RunRecord[]>;
7
+ readonly getRun?: (projectRoot: string, runId: string) => Promise<RunRecord | null>;
8
+ readonly resolveJoin?: (projectRoot: string, runId: string) => Promise<RunJoinTarget | null>;
9
+ readonly dispatch?: (input: {
10
+ readonly projectRoot: string;
11
+ readonly taskId: string;
12
+ readonly title?: string | null;
13
+ readonly force?: boolean;
14
+ readonly model?: string | null;
15
+ readonly prompt?: string | null;
16
+ }) => Promise<{
17
+ readonly runId: string;
18
+ }>;
19
+ readonly listTasks?: (projectRoot: string) => Promise<readonly RunTaskLike[]>;
20
+ readonly deliverRemote?: (projectRoot: string, target: RunRecord, control: RunControl) => Promise<void>;
21
+ }
22
+ export declare function executeRun(context: RunnerContext, args: string[], deps?: RunExecutorDeps): Promise<CommandOutcome>;