@h-rig/cli 0.0.6-alpha.100 → 0.0.6-alpha.102

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 (112) hide show
  1. package/README.md +6 -27
  2. package/bin/rig.js +16 -0
  3. package/package.json +14 -40
  4. package/dist/bin/build-rig-binaries.d.ts +0 -2
  5. package/dist/bin/build-rig-binaries.js +0 -119
  6. package/dist/bin/rig.d.ts +0 -72
  7. package/dist/bin/rig.js +0 -17875
  8. package/dist/config/rig-default-config.yml +0 -5
  9. package/dist/src/app/drone-ui.d.ts +0 -34
  10. package/dist/src/app/drone-ui.js +0 -278
  11. package/dist/src/commands/_async-ui.d.ts +0 -10
  12. package/dist/src/commands/_async-ui.js +0 -121
  13. package/dist/src/commands/_cli-format.d.ts +0 -56
  14. package/dist/src/commands/_cli-format.js +0 -319
  15. package/dist/src/commands/_config-env.d.ts +0 -18
  16. package/dist/src/commands/_config-env.js +0 -22
  17. package/dist/src/commands/_connection-state.d.ts +0 -54
  18. package/dist/src/commands/_connection-state.js +0 -187
  19. package/dist/src/commands/_doctor-checks.d.ts +0 -46
  20. package/dist/src/commands/_doctor-checks.js +0 -352
  21. package/dist/src/commands/_help-catalog.d.ts +0 -29
  22. package/dist/src/commands/_help-catalog.js +0 -146
  23. package/dist/src/commands/_inprocess-services.d.ts +0 -33
  24. package/dist/src/commands/_inprocess-services.js +0 -102
  25. package/dist/src/commands/_json-output.d.ts +0 -11
  26. package/dist/src/commands/_json-output.js +0 -60
  27. package/dist/src/commands/_lazy-reconcile.d.ts +0 -34
  28. package/dist/src/commands/_lazy-reconcile.js +0 -102
  29. package/dist/src/commands/_parsers.d.ts +0 -15
  30. package/dist/src/commands/_parsers.js +0 -114
  31. package/dist/src/commands/_paths.d.ts +0 -11
  32. package/dist/src/commands/_paths.js +0 -50
  33. package/dist/src/commands/_pi-frontend.d.ts +0 -35
  34. package/dist/src/commands/_pi-frontend.js +0 -64
  35. package/dist/src/commands/_pi-install.d.ts +0 -42
  36. package/dist/src/commands/_pi-install.js +0 -167
  37. package/dist/src/commands/_policy.d.ts +0 -8
  38. package/dist/src/commands/_policy.js +0 -127
  39. package/dist/src/commands/_probes.d.ts +0 -1
  40. package/dist/src/commands/_probes.js +0 -13
  41. package/dist/src/commands/_run-bridge.d.ts +0 -114
  42. package/dist/src/commands/_run-bridge.js +0 -387
  43. package/dist/src/commands/_run-diagnostics.d.ts +0 -9
  44. package/dist/src/commands/_run-diagnostics.js +0 -51
  45. package/dist/src/commands/_run-driver-helpers.d.ts +0 -26
  46. package/dist/src/commands/_run-driver-helpers.js +0 -138
  47. package/dist/src/commands/_run-projection.d.ts +0 -50
  48. package/dist/src/commands/_run-projection.js +0 -349
  49. package/dist/src/commands/_run-subcommands.d.ts +0 -3
  50. package/dist/src/commands/_run-subcommands.js +0 -31
  51. package/dist/src/commands/_spinner.d.ts +0 -25
  52. package/dist/src/commands/_spinner.js +0 -65
  53. package/dist/src/commands/agent.d.ts +0 -3
  54. package/dist/src/commands/agent.js +0 -8952
  55. package/dist/src/commands/config.d.ts +0 -3
  56. package/dist/src/commands/config.js +0 -181
  57. package/dist/src/commands/dist.d.ts +0 -28
  58. package/dist/src/commands/dist.js +0 -417
  59. package/dist/src/commands/doctor.d.ts +0 -3
  60. package/dist/src/commands/doctor.js +0 -480
  61. package/dist/src/commands/github.d.ts +0 -3
  62. package/dist/src/commands/github.js +0 -342
  63. package/dist/src/commands/inbox.d.ts +0 -28
  64. package/dist/src/commands/inbox.js +0 -579
  65. package/dist/src/commands/init.d.ts +0 -64
  66. package/dist/src/commands/init.js +0 -1541
  67. package/dist/src/commands/inspect.d.ts +0 -20
  68. package/dist/src/commands/inspect.js +0 -764
  69. package/dist/src/commands/pi.d.ts +0 -3
  70. package/dist/src/commands/pi.js +0 -177
  71. package/dist/src/commands/plugin.d.ts +0 -16
  72. package/dist/src/commands/plugin.js +0 -714
  73. package/dist/src/commands/profile-and-review.d.ts +0 -4
  74. package/dist/src/commands/profile-and-review.js +0 -223
  75. package/dist/src/commands/queue.d.ts +0 -3
  76. package/dist/src/commands/queue.js +0 -197
  77. package/dist/src/commands/remote.d.ts +0 -3
  78. package/dist/src/commands/remote.js +0 -1340
  79. package/dist/src/commands/repo-git-harness.d.ts +0 -5
  80. package/dist/src/commands/repo-git-harness.js +0 -271
  81. package/dist/src/commands/run.d.ts +0 -21
  82. package/dist/src/commands/run.js +0 -17867
  83. package/dist/src/commands/server.d.ts +0 -3
  84. package/dist/src/commands/server.js +0 -249
  85. package/dist/src/commands/setup.d.ts +0 -16
  86. package/dist/src/commands/setup.js +0 -644
  87. package/dist/src/commands/stats.d.ts +0 -15
  88. package/dist/src/commands/stats.js +0 -632
  89. package/dist/src/commands/task-run-driver.d.ts +0 -94
  90. package/dist/src/commands/task-run-driver.js +0 -203
  91. package/dist/src/commands/task.d.ts +0 -35
  92. package/dist/src/commands/task.js +0 -818
  93. package/dist/src/commands/test.d.ts +0 -3
  94. package/dist/src/commands/test.js +0 -46
  95. package/dist/src/commands/triage.d.ts +0 -11
  96. package/dist/src/commands/triage.js +0 -227
  97. package/dist/src/commands/workspace.d.ts +0 -3
  98. package/dist/src/commands/workspace.js +0 -130
  99. package/dist/src/commands.d.ts +0 -13
  100. package/dist/src/commands.js +0 -17999
  101. package/dist/src/index.d.ts +0 -4
  102. package/dist/src/index.js +0 -18011
  103. package/dist/src/launcher.d.ts +0 -61
  104. package/dist/src/launcher.js +0 -199
  105. package/dist/src/operator-cli.d.ts +0 -2
  106. package/dist/src/operator-cli.js +0 -17867
  107. package/dist/src/operator-entry.d.ts +0 -1
  108. package/dist/src/operator-entry.js +0 -3
  109. package/dist/src/runner.d.ts +0 -47
  110. package/dist/src/runner.js +0 -267
  111. package/dist/src/withMutedConsole.d.ts +0 -2
  112. package/dist/src/withMutedConsole.js +0 -42
@@ -1,5 +0,0 @@
1
- import { type RunnerContext } from "../runner";
2
- import type { CommandOutcome } from "@rig/runtime";
3
- export declare function executeRepo(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
4
- export declare function executeGit(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
5
- export declare function executeHarness(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
@@ -1,271 +0,0 @@
1
- // @bun
2
- // packages/cli/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/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/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/src/commands/_policy.ts
103
- import { appendFileSync, existsSync, mkdirSync, readFileSync } from "fs";
104
- import { resolve as resolve2 } from "path";
105
-
106
- // packages/cli/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/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
- id: typeof value.id === "string" && value.id.trim() ? value.id.trim() : `rule-${index + 1}`,
130
- reason: typeof value.reason === "string" && value.reason.trim() ? value.reason.trim() : undefined,
131
- match: typeof value.match === "string" && value.match.trim() ? value.match.trim() : undefined,
132
- command: typeof value.command === "string" && value.command.trim() ? value.command.trim() : undefined
133
- })) : [];
134
- return { mode, rules };
135
- } catch {
136
- return { mode: "observe", rules: [] };
137
- }
138
- }
139
- function matchingRules(command, rules) {
140
- return rules.filter((rule) => {
141
- const rawPattern = rule.command ?? rule.match;
142
- if (!rawPattern)
143
- return false;
144
- try {
145
- return new RegExp(rawPattern, "i").test(command);
146
- } catch {
147
- return command.includes(rawPattern);
148
- }
149
- });
150
- }
151
- function resolveEffectivePolicyMode(context) {
152
- const envMode = process.env.RIG_BASH_MODE;
153
- if (envMode === "off" || envMode === "observe" || envMode === "enforce") {
154
- return envMode;
155
- }
156
- return context.policyMode ?? loadPolicyFile(context.projectRoot).mode;
157
- }
158
- function appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action) {
159
- if (mode === "off") {
160
- return;
161
- }
162
- const logsDir = resolveControlPlaneHostLogsDir(context.projectRoot);
163
- const logFile = resolve2(logsDir, "controlled-bash.jsonl");
164
- mkdirSync(logsDir, { recursive: true });
165
- const payload = {
166
- timestamp: new Date().toISOString(),
167
- mode,
168
- cwd: process.cwd(),
169
- pid: process.pid,
170
- ppid: process.ppid,
171
- argv: args,
172
- command,
173
- matchedRuleIds
174
- };
175
- if (action) {
176
- payload.action = action;
177
- }
178
- appendFileSync(logFile, `${JSON.stringify(payload)}
179
- `, "utf-8");
180
- }
181
- async function enforceNativeCommandPolicy(context, args, options) {
182
- const mode = resolveEffectivePolicyMode(context);
183
- const command = formatCommand([options.commandPrefix, ...args]);
184
- const rules = matchingRules(command, loadPolicyFile(context.projectRoot).rules);
185
- const matchedRuleIds = rules.map((rule) => rule.id);
186
- const action = rules.length === 0 ? "allow" : mode === "enforce" ? "block" : "warn";
187
- await context.emitEvent("policy.decision", {
188
- target: "command",
189
- command,
190
- mode,
191
- allowed: action !== "block",
192
- matchedRuleIds,
193
- reasons: rules.map((rule) => rule.reason).filter(Boolean)
194
- });
195
- if (options.writeAuditLog) {
196
- appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action === "block" ? "blocked" : action === "warn" ? "warn" : undefined);
197
- }
198
- if (action === "block") {
199
- throw new CliError(`Policy blocked command: ${command}`, 126, {
200
- hint: "Review rig/policy/policy.json, or re-run with `--policy-mode observe` to log instead of block."
201
- });
202
- }
203
- }
204
-
205
- // packages/cli/src/commands/repo-git-harness.ts
206
- async function executeRepo(context, args) {
207
- const [command = "sync", ...rest] = args;
208
- switch (command) {
209
- case "sync": {
210
- const { value: task, rest: remaining } = takeOption(rest, "--task");
211
- requireNoExtraArgs(remaining, "rig repo sync [--task <task-id>]");
212
- withMutedConsole(context.outputMode === "json", () => repoEnsure(context.projectRoot, task || undefined));
213
- return { ok: true, group: "repo", command, details: { task: task || null } };
214
- }
215
- case "reset-baseline": {
216
- const { value: keepTaskStatusFlag, rest: remaining } = takeFlag(rest, "--keep-task-status");
217
- requireNoExtraArgs(remaining, "rig repo reset-baseline [--keep-task-status]");
218
- withMutedConsole(context.outputMode === "json", () => resetBaseline(context.projectRoot, keepTaskStatusFlag));
219
- return { ok: true, group: "repo", command, details: { keepTaskStatus: keepTaskStatusFlag } };
220
- }
221
- default:
222
- throw new CliError(`Unknown repo command: ${command}`, 1, { hint: "Run `rig repo --help` \u2014 commands are sync|reset-baseline." });
223
- }
224
- }
225
- async function executeGit(context, args) {
226
- if (args.length === 0) {
227
- throw new CliError("Usage: rig git <git-flow args...>");
228
- }
229
- await enforceNativeCommandPolicy(context, args, {
230
- commandPrefix: "rig-agent git",
231
- writeAuditLog: false
232
- });
233
- if (context.dryRun) {
234
- if (context.outputMode === "text") {
235
- console.log(`[dry-run] rig git ${args.join(" ")}`);
236
- }
237
- return { ok: true, group: "git", command: args[0] ?? "git" };
238
- }
239
- try {
240
- await executeHarnessCommand(context.projectRoot, ["git", ...args]);
241
- } catch (error) {
242
- throw new CliError(error instanceof Error ? error.message : String(error), 2);
243
- }
244
- return { ok: true, group: "git", command: args[0] ?? "git" };
245
- }
246
- async function executeHarness(context, args) {
247
- if (args.length === 0) {
248
- throw new CliError("Usage: rig harness <harness args...>");
249
- }
250
- await enforceNativeCommandPolicy(context, args, {
251
- commandPrefix: "rig-agent",
252
- writeAuditLog: true
253
- });
254
- if (context.dryRun) {
255
- if (context.outputMode === "text") {
256
- console.log(`[dry-run] rig harness ${args.join(" ")}`);
257
- }
258
- return { ok: true, group: "harness", command: args[0] ?? "harness" };
259
- }
260
- try {
261
- await executeHarnessCommand(context.projectRoot, args);
262
- } catch (error) {
263
- throw new CliError(error instanceof Error ? error.message : String(error), 2);
264
- }
265
- return { ok: true, group: "harness", command: args[0] ?? "harness" };
266
- }
267
- export {
268
- executeRepo,
269
- executeHarness,
270
- executeGit
271
- };
@@ -1,21 +0,0 @@
1
- import { type RunnerContext } from "../runner";
2
- import type { CommandOutcome } from "@rig/runtime";
3
- import { type RigExtensionTask, type RunControl } from "./_run-bridge";
4
- import { type RunJoinTarget, type RunProjectionRecord } from "./_run-projection";
5
- export type RunTaskLike = RigExtensionTask & Record<string, unknown>;
6
- export interface RunExecutorDeps {
7
- readonly listRuns?: (projectRoot: string) => Promise<RunProjectionRecord[]>;
8
- readonly getRun?: (projectRoot: string, runId: string) => Promise<RunProjectionRecord | null>;
9
- readonly resolveJoin?: (projectRoot: string, runId: string) => Promise<RunJoinTarget | null>;
10
- readonly dispatch?: (input: {
11
- readonly projectRoot: string;
12
- readonly taskId: string;
13
- readonly title?: string | null;
14
- }) => Promise<{
15
- readonly runId: string;
16
- }>;
17
- readonly listTasks?: (projectRoot: string) => Promise<readonly RunTaskLike[]>;
18
- readonly appendLocal?: (record: RunProjectionRecord, text: string) => Promise<void>;
19
- readonly deliverRemote?: (projectRoot: string, runId: string, control: RunControl) => Promise<void>;
20
- }
21
- export declare function executeRun(context: RunnerContext, args: string[], deps?: RunExecutorDeps): Promise<CommandOutcome>;