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

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 (120) hide show
  1. package/README.md +18 -19
  2. package/dist/bin/build-rig-binaries.d.ts +2 -0
  3. package/dist/bin/build-rig-binaries.js +22 -10
  4. package/dist/bin/rig.d.ts +72 -0
  5. package/dist/bin/rig.js +15742 -7203
  6. package/dist/config/rig-default-config.yml +5 -0
  7. package/dist/src/app/drone-ui.d.ts +34 -0
  8. package/dist/src/app/drone-ui.js +278 -0
  9. package/dist/src/commands/_async-ui.d.ts +10 -0
  10. package/dist/src/commands/_async-ui.js +121 -0
  11. package/dist/src/commands/_cli-format.d.ts +56 -0
  12. package/dist/src/commands/_cli-format.js +319 -0
  13. package/dist/src/commands/_config-env.d.ts +18 -0
  14. package/dist/src/commands/_config-env.js +22 -0
  15. package/dist/src/commands/_connection-state.d.ts +54 -0
  16. package/dist/src/commands/_connection-state.js +75 -11
  17. package/dist/src/commands/_doctor-checks.d.ts +46 -0
  18. package/dist/src/commands/_doctor-checks.js +95 -244
  19. package/dist/src/commands/_help-catalog.d.ts +29 -0
  20. package/dist/src/commands/_help-catalog.js +146 -0
  21. package/dist/src/commands/_inprocess-services.d.ts +33 -0
  22. package/dist/src/commands/_inprocess-services.js +102 -0
  23. package/dist/src/commands/_json-output.d.ts +11 -0
  24. package/dist/src/commands/_json-output.js +60 -0
  25. package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
  26. package/dist/src/commands/_lazy-reconcile.js +102 -0
  27. package/dist/src/commands/_parsers.d.ts +15 -0
  28. package/dist/src/commands/_parsers.js +18 -11
  29. package/dist/src/commands/_paths.d.ts +11 -0
  30. package/dist/src/commands/_paths.js +1 -1
  31. package/dist/src/commands/_pi-frontend.d.ts +35 -0
  32. package/dist/src/commands/_pi-frontend.js +64 -0
  33. package/dist/src/commands/_pi-install.d.ts +42 -0
  34. package/dist/src/commands/_pi-install.js +19 -36
  35. package/dist/src/commands/_policy.d.ts +8 -0
  36. package/dist/src/commands/_policy.js +67 -19
  37. package/dist/src/commands/_probes.d.ts +1 -0
  38. package/dist/src/commands/_run-bridge.d.ts +114 -0
  39. package/dist/src/commands/_run-bridge.js +387 -0
  40. package/dist/src/commands/_run-diagnostics.d.ts +9 -0
  41. package/dist/src/commands/_run-diagnostics.js +51 -0
  42. package/dist/src/commands/_run-driver-helpers.d.ts +26 -0
  43. package/dist/src/commands/_run-driver-helpers.js +79 -230
  44. package/dist/src/commands/_run-projection.d.ts +50 -0
  45. package/dist/src/commands/_run-projection.js +349 -0
  46. package/dist/src/commands/_run-subcommands.d.ts +3 -0
  47. package/dist/src/commands/_run-subcommands.js +31 -0
  48. package/dist/src/commands/_spinner.d.ts +25 -0
  49. package/dist/src/commands/_spinner.js +65 -0
  50. package/dist/src/commands/agent.d.ts +3 -0
  51. package/dist/src/commands/agent.js +8690 -235
  52. package/dist/src/commands/config.d.ts +3 -0
  53. package/dist/src/commands/config.js +181 -0
  54. package/dist/src/commands/dist.d.ts +28 -0
  55. package/dist/src/commands/dist.js +44 -29
  56. package/dist/src/commands/doctor.d.ts +3 -0
  57. package/dist/src/commands/doctor.js +214 -245
  58. package/dist/src/commands/github.d.ts +3 -0
  59. package/dist/src/commands/github.js +237 -171
  60. package/dist/src/commands/inbox.d.ts +28 -0
  61. package/dist/src/commands/inbox.js +530 -111
  62. package/dist/src/commands/init.d.ts +64 -0
  63. package/dist/src/commands/init.js +941 -654
  64. package/dist/src/commands/inspect.d.ts +20 -0
  65. package/dist/src/commands/inspect.js +709 -119
  66. package/dist/src/commands/pi.d.ts +3 -0
  67. package/dist/src/commands/pi.js +177 -0
  68. package/dist/src/commands/plugin.d.ts +16 -0
  69. package/dist/src/commands/plugin.js +576 -29
  70. package/dist/src/commands/profile-and-review.d.ts +4 -0
  71. package/dist/src/commands/profile-and-review.js +112 -67
  72. package/dist/src/commands/queue.d.ts +3 -0
  73. package/dist/src/commands/queue.js +20 -20
  74. package/dist/src/commands/remote.d.ts +3 -0
  75. package/dist/src/commands/remote.js +883 -50
  76. package/dist/src/commands/repo-git-harness.d.ts +5 -0
  77. package/dist/src/commands/repo-git-harness.js +78 -28
  78. package/dist/src/commands/run.d.ts +21 -0
  79. package/dist/src/commands/run.js +17732 -618
  80. package/dist/src/commands/server.d.ts +3 -0
  81. package/dist/src/commands/server.js +166 -285
  82. package/dist/src/commands/setup.d.ts +16 -0
  83. package/dist/src/commands/setup.js +230 -267
  84. package/dist/src/commands/stats.d.ts +15 -0
  85. package/dist/src/commands/stats.js +632 -0
  86. package/dist/src/commands/task-run-driver.d.ts +94 -0
  87. package/dist/src/commands/task-run-driver.js +120 -1856
  88. package/dist/src/commands/task.d.ts +35 -0
  89. package/dist/src/commands/task.js +676 -1183
  90. package/dist/src/commands/test.d.ts +3 -0
  91. package/dist/src/commands/test.js +15 -8
  92. package/dist/src/commands/triage.d.ts +11 -0
  93. package/dist/src/commands/triage.js +227 -0
  94. package/dist/src/commands/workspace.d.ts +3 -0
  95. package/dist/src/commands/workspace.js +18 -11
  96. package/dist/src/commands.d.ts +13 -0
  97. package/dist/src/commands.js +16760 -7779
  98. package/dist/src/index.d.ts +4 -0
  99. package/dist/src/index.js +16880 -8223
  100. package/dist/src/launcher.d.ts +61 -0
  101. package/dist/src/launcher.js +81 -13
  102. package/dist/src/operator-cli.d.ts +2 -0
  103. package/dist/src/operator-cli.js +17867 -0
  104. package/dist/src/operator-entry.d.ts +1 -0
  105. package/dist/src/operator-entry.js +3 -0
  106. package/dist/src/runner.d.ts +47 -0
  107. package/dist/src/runner.js +19 -24
  108. package/dist/src/withMutedConsole.d.ts +2 -0
  109. package/package.json +21 -7
  110. package/dist/src/commands/_authority-runs.js +0 -110
  111. package/dist/src/commands/_operator-view.js +0 -322
  112. package/dist/src/commands/_preflight.js +0 -460
  113. package/dist/src/commands/_server-client.js +0 -364
  114. package/dist/src/commands/_snapshot-upload.js +0 -313
  115. package/dist/src/commands/_task-picker.js +0 -48
  116. package/dist/src/commands/browser.js +0 -890
  117. package/dist/src/commands/connect.js +0 -180
  118. package/dist/src/commands/inspector.js +0 -256
  119. package/dist/src/commands/task-report-bug.js +0 -1083
  120. package/dist/src/report-bug.js +0 -260
@@ -0,0 +1,3 @@
1
+ import { type RunnerContext } from "../runner";
2
+ import type { CommandOutcome } from "@rig/runtime";
3
+ export declare function executePi(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
@@ -0,0 +1,177 @@
1
+ // @bun
2
+ // packages/cli/src/commands/pi.ts
3
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
4
+ import { homedir } from "os";
5
+ import { dirname, resolve } from "path";
6
+
7
+ // packages/cli/src/runner.ts
8
+ import { EventBus } from "@rig/runtime/control-plane/runtime/events";
9
+ import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
10
+ import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
11
+ import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
12
+
13
+ class CliError extends RuntimeCliError {
14
+ hint;
15
+ constructor(message, exitCode = 1, options = {}) {
16
+ super(message, exitCode);
17
+ if (options.hint?.trim()) {
18
+ this.hint = options.hint.trim();
19
+ }
20
+ }
21
+ }
22
+ function requireNoExtraArgs(args, usage) {
23
+ if (args.length > 0) {
24
+ throw new CliError(`Unexpected arguments: ${args.join(" ")}
25
+ Usage: ${usage}`);
26
+ }
27
+ }
28
+
29
+ // packages/cli/src/commands/pi.ts
30
+ function settingsPath(root) {
31
+ return resolve(root, ".pi", "settings.json");
32
+ }
33
+ function userSettingsPath() {
34
+ return resolve(homedir(), ".pi", "agent", "settings.json");
35
+ }
36
+ function readJson(path, fallback) {
37
+ if (!existsSync(path))
38
+ return fallback;
39
+ try {
40
+ return JSON.parse(readFileSync(path, "utf-8"));
41
+ } catch {
42
+ return fallback;
43
+ }
44
+ }
45
+ function packageKey(entry) {
46
+ if (typeof entry === "string")
47
+ return entry;
48
+ if (entry && typeof entry === "object" && typeof entry.source === "string") {
49
+ return entry.source;
50
+ }
51
+ return JSON.stringify(entry);
52
+ }
53
+ function writeSettings(path, settings) {
54
+ mkdirSync(dirname(path), { recursive: true });
55
+ writeFileSync(path, `${JSON.stringify(settings, null, 2)}
56
+ `, "utf-8");
57
+ }
58
+ async function searchNpmForPiExtensions(term) {
59
+ const query = encodeURIComponent(term ? `${term} pi extension` : "pi extension");
60
+ const url = `https://registry.npmjs.org/-/v1/search?text=${query}&size=20`;
61
+ const response = await fetch(url);
62
+ if (!response.ok) {
63
+ throw new CliError(`npm registry search failed (${response.status}).`, 2, { hint: "Check network access to registry.npmjs.org, then retry `rig pi search <term>`." });
64
+ }
65
+ const payload = await response.json();
66
+ const results = [];
67
+ for (const entry of payload.objects ?? []) {
68
+ const pkg = entry.package;
69
+ if (!pkg?.name)
70
+ continue;
71
+ const keywords = (pkg.keywords ?? []).map((k) => k.toLowerCase());
72
+ const piLike = pkg.name.startsWith("pi-") || pkg.name.includes("-pi") || keywords.includes("pi") || keywords.includes("pi-extension") || (pkg.description ?? "").toLowerCase().includes("pi extension") || (pkg.description ?? "").toLowerCase().includes("pi coding agent");
73
+ if (!piLike)
74
+ continue;
75
+ results.push({ name: pkg.name, version: pkg.version ?? "", description: pkg.description ?? "" });
76
+ }
77
+ return results;
78
+ }
79
+ async function executePi(context, args) {
80
+ const [command = "list", ...rest] = args;
81
+ const projectSettingsPath = settingsPath(context.projectRoot);
82
+ const managedRecordPath = resolve(context.projectRoot, ".rig", "state", "pi-managed-packages.json");
83
+ switch (command) {
84
+ case "list": {
85
+ requireNoExtraArgs(rest, "rig pi list");
86
+ const project = readJson(projectSettingsPath, {});
87
+ const managed = new Set(readJson(managedRecordPath, []));
88
+ const user = readJson(userSettingsPath(), {});
89
+ const projectPackages = (Array.isArray(project.packages) ? project.packages : []).map((entry) => ({
90
+ source: packageKey(entry),
91
+ managedByRigConfig: managed.has(packageKey(entry))
92
+ }));
93
+ const userPackages = (Array.isArray(user.packages) ? user.packages : []).map(packageKey);
94
+ if (context.outputMode === "text") {
95
+ console.log("Project Pi packages (.pi/settings.json):");
96
+ if (projectPackages.length === 0)
97
+ console.log(" (none)");
98
+ for (const pkg of projectPackages) {
99
+ console.log(` ${pkg.source}${pkg.managedByRigConfig ? " [from rig.config runtime.pi.packages]" : ""}`);
100
+ }
101
+ console.log("User Pi packages (~/.pi/agent/settings.json):");
102
+ if (userPackages.length === 0)
103
+ console.log(" (none)");
104
+ for (const pkg of userPackages)
105
+ console.log(` ${pkg}`);
106
+ console.log("Add more: `rig pi add <npm-package>` \xB7 discover: `rig pi search <term>`");
107
+ }
108
+ return { ok: true, group: "pi", command, details: { projectPackages, userPackages } };
109
+ }
110
+ case "add": {
111
+ const [source, ...extra] = rest;
112
+ requireNoExtraArgs(extra, "rig pi add <package-source>");
113
+ if (!source) {
114
+ throw new CliError("Usage: rig pi add <package-source> (npm name, name@version, or git URL)", 2);
115
+ }
116
+ const settings = readJson(projectSettingsPath, {});
117
+ const packages = Array.isArray(settings.packages) ? settings.packages : [];
118
+ if (packages.some((entry) => packageKey(entry) === source)) {
119
+ throw new CliError(`"${source}" is already in ${projectSettingsPath}.`, 2, { hint: "Run `rig pi list` to see installed extensions." });
120
+ }
121
+ writeSettings(projectSettingsPath, { ...settings, packages: [...packages, source] });
122
+ if (context.outputMode === "text") {
123
+ console.log(`Added ${source} to ${projectSettingsPath}.`);
124
+ console.log("Pi installs missing packages automatically at the next session start (local and worker).");
125
+ }
126
+ return { ok: true, group: "pi", command, details: { source, settingsPath: projectSettingsPath } };
127
+ }
128
+ case "remove": {
129
+ const [source, ...extra] = rest;
130
+ requireNoExtraArgs(extra, "rig pi remove <package-source>");
131
+ if (!source) {
132
+ throw new CliError("Usage: rig pi remove <package-source>", 2);
133
+ }
134
+ const managed = new Set(readJson(managedRecordPath, []));
135
+ if (managed.has(source)) {
136
+ throw new CliError(`"${source}" is managed by rig.config.ts (runtime.pi.packages); remove it there instead.`, 2);
137
+ }
138
+ const settings = readJson(projectSettingsPath, {});
139
+ const packages = Array.isArray(settings.packages) ? settings.packages : [];
140
+ const next = packages.filter((entry) => packageKey(entry) !== source);
141
+ if (next.length === packages.length) {
142
+ throw new CliError(`"${source}" is not in ${projectSettingsPath}.`, 2, { hint: "Run `rig pi list` to see what is installed, then `rig pi remove <source>` with an exact entry." });
143
+ }
144
+ const nextSettings = { ...settings };
145
+ if (next.length > 0)
146
+ nextSettings.packages = next;
147
+ else
148
+ delete nextSettings.packages;
149
+ writeSettings(projectSettingsPath, nextSettings);
150
+ if (context.outputMode === "text") {
151
+ console.log(`Removed ${source} from ${projectSettingsPath}.`);
152
+ }
153
+ return { ok: true, group: "pi", command, details: { source } };
154
+ }
155
+ case "search": {
156
+ const term = rest.join(" ").trim();
157
+ const results = await searchNpmForPiExtensions(term);
158
+ if (context.outputMode === "text") {
159
+ if (results.length === 0) {
160
+ console.log(`No Pi extension packages found on npm${term ? ` for "${term}"` : ""}.`);
161
+ } else {
162
+ console.log(`Pi extension packages on npm${term ? ` matching "${term}"` : ""}:`);
163
+ for (const pkg of results) {
164
+ console.log(` ${pkg.name}@${pkg.version} ${pkg.description.slice(0, 80)}`);
165
+ }
166
+ console.log("Install one: `rig pi add <name>`");
167
+ }
168
+ }
169
+ return { ok: true, group: "pi", command, details: { term, results } };
170
+ }
171
+ default:
172
+ throw new CliError(`Unknown pi command: ${command}. Use list|add|remove|search.`, 1, { hint: "Run `rig pi --help` for usage." });
173
+ }
174
+ }
175
+ export {
176
+ executePi
177
+ };
@@ -0,0 +1,16 @@
1
+ import { type RunnerContext } from "../runner";
2
+ import type { CommandOutcome } from "@rig/runtime";
3
+ export declare function executePlugin(context: RunnerContext, 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
+ command: string;
11
+ description?: string;
12
+ }[], requested: string): {
13
+ id: string;
14
+ command: string;
15
+ description?: string;
16
+ } | undefined;