@h-rig/harness-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.
Files changed (82) hide show
  1. package/README.md +1 -0
  2. package/dist/bin/rig-agent-dispatch.d.ts +2 -0
  3. package/dist/bin/rig-agent-dispatch.js +826 -0
  4. package/dist/src/agent-command.d.ts +3 -0
  5. package/dist/src/agent-command.js +233 -0
  6. package/dist/src/agent-harness/agent-mode.d.ts +1 -0
  7. package/dist/src/agent-harness/agent-mode.js +48 -0
  8. package/dist/src/agent-harness/agent-wrapper.d.ts +60 -0
  9. package/dist/src/agent-harness/agent-wrapper.js +842 -0
  10. package/dist/src/agent-harness/controlled-bash.d.ts +3 -0
  11. package/dist/src/agent-harness/controlled-bash.js +45 -0
  12. package/dist/src/agent-harness/git-ops.d.ts +2 -0
  13. package/dist/src/agent-harness/git-ops.js +27 -0
  14. package/dist/src/agent-harness/repo-ops.d.ts +14 -0
  15. package/dist/src/agent-harness/repo-ops.js +37 -0
  16. package/dist/src/agent-harness/rig-agent-entrypoint.d.ts +1 -0
  17. package/dist/src/agent-harness/rig-agent-entrypoint.js +1362 -0
  18. package/dist/src/agent-harness/rig-agent.d.ts +2 -0
  19. package/dist/src/agent-harness/rig-agent.js +1324 -0
  20. package/dist/src/agent-harness/runtime-snapshot-config.d.ts +2 -0
  21. package/dist/src/agent-harness/runtime-snapshot-config.js +25 -0
  22. package/dist/src/agent-harness/task-data.d.ts +27 -0
  23. package/dist/src/agent-harness/task-data.js +286 -0
  24. package/dist/src/agent-harness/task-ops.d.ts +10 -0
  25. package/dist/src/agent-harness/task-ops.js +352 -0
  26. package/dist/src/index.d.ts +6 -0
  27. package/dist/src/index.js +4525 -0
  28. package/dist/src/model.d.ts +80 -0
  29. package/dist/src/model.js +64 -0
  30. package/dist/src/pi-command.d.ts +3 -0
  31. package/dist/src/pi-command.js +154 -0
  32. package/dist/src/pi-settings-materializer.d.ts +10 -0
  33. package/dist/src/pi-settings-materializer.js +52 -0
  34. package/dist/src/plugin.d.ts +24 -0
  35. package/dist/src/plugin.js +4486 -0
  36. package/dist/src/profile-command.d.ts +3 -0
  37. package/dist/src/profile-command.js +79 -0
  38. package/dist/src/profile-state.d.ts +7 -0
  39. package/dist/src/profile-state.js +39 -0
  40. package/dist/src/rig-task-run-skill.d.ts +8 -0
  41. package/dist/src/rig-task-run-skill.js +39 -0
  42. package/dist/src/runtime-instructions.d.ts +4 -0
  43. package/dist/src/runtime-instructions.js +26 -0
  44. package/dist/src/runtime-secrets.d.ts +6 -0
  45. package/dist/src/runtime-secrets.js +58 -0
  46. package/dist/src/service.d.ts +14 -0
  47. package/dist/src/service.js +33 -0
  48. package/dist/src/session-asset-materializer-service.d.ts +13 -0
  49. package/dist/src/session-asset-materializer-service.js +164 -0
  50. package/dist/src/session-hook-materializer-service.d.ts +34 -0
  51. package/dist/src/session-hook-materializer-service.js +142 -0
  52. package/dist/src/skill-materializer.d.ts +25 -0
  53. package/dist/src/skill-materializer.js +86 -0
  54. package/dist/src/tooling/browser-tool-entrypoint.d.ts +2 -0
  55. package/dist/src/tooling/browser-tool-entrypoint.js +125 -0
  56. package/dist/src/tooling/browser-tools.d.ts +3 -0
  57. package/dist/src/tooling/browser-tools.js +27 -0
  58. package/dist/src/tooling/claude-router-binary.d.ts +3 -0
  59. package/dist/src/tooling/claude-router-binary.js +62 -0
  60. package/dist/src/tooling/claude-router.d.ts +22 -0
  61. package/dist/src/tooling/claude-router.js +524 -0
  62. package/dist/src/tooling/embedded-native-assets.d.ts +7 -0
  63. package/dist/src/tooling/embedded-native-assets.js +6 -0
  64. package/dist/src/tooling/file-tools.d.ts +5 -0
  65. package/dist/src/tooling/file-tools.js +192 -0
  66. package/dist/src/tooling/gateway.d.ts +4 -0
  67. package/dist/src/tooling/gateway.js +400 -0
  68. package/dist/src/tooling/shell-tools.d.ts +5 -0
  69. package/dist/src/tooling/shell-tools.js +185 -0
  70. package/native/darwin-arm64/rig-shell +0 -0
  71. package/native/darwin-arm64/rig-shell.build-manifest.json +4 -0
  72. package/native/darwin-arm64/rig-tools +0 -0
  73. package/native/darwin-arm64/rig-tools.build-manifest.json +4 -0
  74. package/native/darwin-x64/rig-shell +0 -0
  75. package/native/darwin-x64/rig-tools +0 -0
  76. package/native/linux-arm64/rig-shell +0 -0
  77. package/native/linux-arm64/rig-tools +0 -0
  78. package/native/linux-x64/rig-shell +0 -0
  79. package/native/linux-x64/rig-tools +0 -0
  80. package/native/win32-x64/rig-shell.exe +0 -0
  81. package/native/win32-x64/rig-tools.exe +0 -0
  82. package/package.json +101 -0
@@ -0,0 +1,3 @@
1
+ import type { RunnerContext } from "@rig/core/runtime-runner-context";
2
+ import type { CommandOutcome } from "@rig/contracts";
3
+ export declare function executeAgent(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
@@ -0,0 +1,233 @@
1
+ // @bun
2
+ // packages/harness-plugin/src/agent-command.ts
3
+ import {
4
+ CliError,
5
+ requireNoExtraArgs,
6
+ takeFlag,
7
+ takeOption
8
+ } from "@rig/std-shared/cli-args";
9
+ import { agentId } from "@rig/core/safe-identifiers";
10
+ import { ISOLATION_BACKEND, REPO_OPERATIONS_CAPABILITY } from "@rig/contracts";
11
+ import { defineCapability } from "@rig/core/capability";
12
+ import { requireCapabilityForRoot } from "@rig/core/capability-loaders";
13
+ import { buildPluginHostContext } from "@rig/core/plugin-host-context";
14
+ import { withMutedConsole } from "@rig/std-shared/cli-muted-console";
15
+ import { parseEnumOption } from "@rig/std-shared/cli-args";
16
+ var MISSING_ISOLATION_BACKEND_HINT = "Install @rig/isolation-plugin (it ships in the default bundle) so runtime provisioning can resolve a backend.";
17
+ var RepoOperationsCap = defineCapability(REPO_OPERATIONS_CAPABILITY);
18
+ async function resolveRepoOperations(projectRoot) {
19
+ const hostCtx = await buildPluginHostContext(projectRoot);
20
+ const repoOps = hostCtx ? await RepoOperationsCap.resolve(hostCtx.pluginHost) : null;
21
+ if (!repoOps) {
22
+ throw new CliError(`No REPO_OPERATIONS capability is registered for project root "${projectRoot}".`, 2, { hint: "Install @rig/repos-plugin (it ships in the default bundle) before running repo operations." });
23
+ }
24
+ return repoOps;
25
+ }
26
+ async function resolveIsolationBackend(projectRoot) {
27
+ return requireCapabilityForRoot(projectRoot, defineCapability(ISOLATION_BACKEND), `No ISOLATION_BACKEND capability is registered for project root "${projectRoot}". ` + MISSING_ISOLATION_BACKEND_HINT);
28
+ }
29
+ function splitAtDoubleDash(args) {
30
+ const separatorIndex = args.indexOf("--");
31
+ if (separatorIndex === -1) {
32
+ return { options: args, commandParts: [] };
33
+ }
34
+ return {
35
+ options: args.slice(0, separatorIndex),
36
+ commandParts: args.slice(separatorIndex + 1)
37
+ };
38
+ }
39
+ async function attachEventBusToProvisionedRuntime(context, workspaceDir) {
40
+ const previousWorkspace = process.env.RIG_TASK_WORKSPACE;
41
+ process.env.RIG_TASK_WORKSPACE = workspaceDir;
42
+ try {
43
+ await context.eventBus.attachRuntimeWorkspace(context.projectRoot);
44
+ } finally {
45
+ if (previousWorkspace === undefined) {
46
+ delete process.env.RIG_TASK_WORKSPACE;
47
+ } else {
48
+ process.env.RIG_TASK_WORKSPACE = previousWorkspace;
49
+ }
50
+ }
51
+ }
52
+ async function runProjectMainSyncPreflight(context, options) {
53
+ if (context.dryRun) {
54
+ if (context.outputMode === "text" && !options.disabled) {
55
+ console.log("[dry-run] project-rig pre-run sync check");
56
+ }
57
+ return;
58
+ }
59
+ const repoOps = await resolveRepoOperations(context.projectRoot);
60
+ const result = await repoOps.ensureProjectMainFreshBeforeRun({
61
+ projectRoot: context.projectRoot,
62
+ disabled: options.disabled,
63
+ runBootstrap: async () => {
64
+ const bootstrap = await context.runCommand(["bun", "run", "bootstrap"]);
65
+ if (bootstrap.exitCode !== 0) {
66
+ throw new CliError(bootstrap.stderr || bootstrap.stdout || "bun run bootstrap failed during project pre-run sync", bootstrap.exitCode || 1);
67
+ }
68
+ }
69
+ });
70
+ if (context.outputMode !== "text") {
71
+ return;
72
+ }
73
+ switch (result.status) {
74
+ case "disabled":
75
+ console.log("Project pre-run sync skipped (--skip-project-sync).");
76
+ break;
77
+ case "skipped_not_main":
78
+ console.log(`Project pre-run sync skipped (current branch: ${result.branch}).`);
79
+ break;
80
+ case "up_to_date":
81
+ break;
82
+ case "local_ahead":
83
+ console.log(`Project pre-run sync skipped (local main ahead by ${result.localAhead} commit(s)).`);
84
+ break;
85
+ case "updated":
86
+ console.log(`Project pre-run sync updated local main from origin/main (+${result.remoteAhead}) and bootstrapped.`);
87
+ break;
88
+ }
89
+ }
90
+ async function executeAgent(context, args) {
91
+ const [command = "list", ...rest] = args;
92
+ const backend = await resolveIsolationBackend(context.projectRoot);
93
+ switch (command) {
94
+ case "list": {
95
+ requireNoExtraArgs(rest, "rig agent list");
96
+ const runtimes = await backend.listAgentRuntimes(context.projectRoot);
97
+ if (context.outputMode === "text") {
98
+ if (runtimes.length === 0) {
99
+ console.log("No agent runtimes.");
100
+ } else {
101
+ for (const runtime of runtimes) {
102
+ console.log(`${runtime.id} (${runtime.mode}) workspace=${runtime.workspaceDir} created=${runtime.createdAt}`);
103
+ }
104
+ }
105
+ }
106
+ return { ok: true, group: "agent", command, details: { runtimes } };
107
+ }
108
+ case "prepare": {
109
+ let pending = rest;
110
+ const idResult = takeOption(pending, "--id");
111
+ pending = idResult.rest;
112
+ const modeResult = takeOption(pending, "--mode");
113
+ pending = modeResult.rest;
114
+ const taskResult = takeOption(pending, "--task");
115
+ pending = taskResult.rest;
116
+ requireNoExtraArgs(pending, "rig agent prepare --task <id> [--id <id>] [--mode worktree]");
117
+ const mode = parseEnumOption(modeResult.value, ["worktree"], { fallback: "worktree", label: "isolation mode" });
118
+ const id = idResult.value || agentId("agent");
119
+ const taskId = taskResult.value?.trim();
120
+ if (!taskId) {
121
+ throw new CliError("Usage: rig agent prepare --task <id> [--id <id>] [--mode worktree]");
122
+ }
123
+ const runtime = await withMutedConsole(context.outputMode === "json", () => backend.ensureAgentRuntime({
124
+ projectRoot: context.projectRoot,
125
+ id,
126
+ taskId,
127
+ mode
128
+ }));
129
+ await attachEventBusToProvisionedRuntime(context, runtime.workspaceDir);
130
+ if (context.outputMode === "text") {
131
+ console.log(`Prepared runtime ${runtime.id} (${runtime.mode})`);
132
+ console.log(`Workspace: ${runtime.workspaceDir}`);
133
+ }
134
+ return { ok: true, group: "agent", command, details: { runtime } };
135
+ }
136
+ case "run": {
137
+ const { options, commandParts } = splitAtDoubleDash(rest);
138
+ if (commandParts.length === 0) {
139
+ throw new CliError("Usage: rig agent run [--id <id>] [--mode worktree] [--skip-project-sync] -- <command...>");
140
+ }
141
+ let pending = options;
142
+ const idResult = takeOption(pending, "--id");
143
+ pending = idResult.rest;
144
+ const modeResult = takeOption(pending, "--mode");
145
+ pending = modeResult.rest;
146
+ const taskResult = takeOption(pending, "--task");
147
+ pending = taskResult.rest;
148
+ const skipProjectSyncResult = takeFlag(pending, "--skip-project-sync");
149
+ pending = skipProjectSyncResult.rest;
150
+ requireNoExtraArgs(pending, "rig agent run --task <id> [--id <id>] [--mode worktree] [--skip-project-sync] -- <command...>");
151
+ const mode = parseEnumOption(modeResult.value, ["worktree"], { fallback: "worktree", label: "isolation mode" });
152
+ const id = idResult.value || agentId("agent-run");
153
+ const taskId = taskResult.value?.trim();
154
+ if (!taskId) {
155
+ throw new CliError("Usage: rig agent run --task <id> [--id <id>] [--mode worktree] [--skip-project-sync] -- <command...>");
156
+ }
157
+ await runProjectMainSyncPreflight(context, { disabled: skipProjectSyncResult.value });
158
+ try {
159
+ const runtime = await withMutedConsole(context.outputMode === "json", () => backend.ensureAgentRuntime({
160
+ projectRoot: context.projectRoot,
161
+ id,
162
+ taskId,
163
+ mode
164
+ }));
165
+ await attachEventBusToProvisionedRuntime(context, runtime.workspaceDir);
166
+ const result = await backend.runInAgentRuntime({
167
+ projectRoot: context.projectRoot,
168
+ runtime,
169
+ command: commandParts,
170
+ inheritStdio: context.outputMode === "text"
171
+ });
172
+ if (result.exitCode !== 0) {
173
+ throw new CliError(`Agent runtime command failed (${result.exitCode}) in ${runtime.id}${result.stderr ? `
174
+ ${result.stderr.trim()}` : ""}`, result.exitCode);
175
+ }
176
+ return {
177
+ ok: true,
178
+ group: "agent",
179
+ command,
180
+ details: {
181
+ runtimeId: runtime.id,
182
+ mode: runtime.mode,
183
+ command: commandParts,
184
+ exitCode: result.exitCode,
185
+ sandboxBackend: result.sandboxBackend,
186
+ sandboxEnabled: result.sandboxEnabled,
187
+ stdout: result.stdout,
188
+ stderr: result.stderr
189
+ }
190
+ };
191
+ } catch (error) {
192
+ throw error;
193
+ }
194
+ }
195
+ case "cleanup": {
196
+ let pending = rest;
197
+ const allResult = takeFlag(pending, "--all");
198
+ pending = allResult.rest;
199
+ const idResult = takeOption(pending, "--id");
200
+ pending = idResult.rest;
201
+ requireNoExtraArgs(pending, "rig agent cleanup (--id <id> | --all)");
202
+ if (!allResult.value && !idResult.value) {
203
+ throw new CliError("Provide --id <id> or --all.", 1, { hint: "Run `rig agent list` to find agent ids." });
204
+ }
205
+ const runtimes = await backend.listAgentRuntimes(context.projectRoot);
206
+ const targets = allResult.value ? runtimes.map((runtime) => runtime.id) : [idResult.value];
207
+ for (const id of targets) {
208
+ await backend.cleanupAgentRuntime({
209
+ projectRoot: context.projectRoot,
210
+ id
211
+ });
212
+ }
213
+ if (context.outputMode === "text") {
214
+ console.log(`Cleaned runtimes: ${targets.join(", ")}`);
215
+ }
216
+ return {
217
+ ok: true,
218
+ group: "agent",
219
+ command,
220
+ details: {
221
+ cleaned: targets,
222
+ count: targets.length,
223
+ all: allResult.value
224
+ }
225
+ };
226
+ }
227
+ default:
228
+ throw new CliError(`Unknown agent command: ${command}`, 1, { hint: "Run `rig agent --help` to list agent commands." });
229
+ }
230
+ }
231
+ export {
232
+ executeAgent
233
+ };
@@ -0,0 +1 @@
1
+ export declare function looksLikeShellInvocation(args: string[], mode?: string | undefined): boolean;
@@ -0,0 +1,48 @@
1
+ // @bun
2
+ // packages/harness-plugin/src/agent-harness/agent-mode.ts
3
+ function looksLikeShellInvocation(args, mode = process.env.RIG_AGENT_MODE) {
4
+ if (mode === "shell") {
5
+ return true;
6
+ }
7
+ if (mode === "agent") {
8
+ return false;
9
+ }
10
+ if (args.length === 0) {
11
+ return false;
12
+ }
13
+ const first = args[0];
14
+ if (!first) {
15
+ return false;
16
+ }
17
+ const bashLikeFlags = new Set([
18
+ "-c",
19
+ "-lc",
20
+ "-l",
21
+ "-i",
22
+ "-s",
23
+ "--login",
24
+ "--noprofile",
25
+ "--norc",
26
+ "--posix",
27
+ "--rcfile",
28
+ "--init-file",
29
+ "--restricted",
30
+ "--debug",
31
+ "--debugger",
32
+ "--verbose",
33
+ "--wordexp",
34
+ "--dump-strings",
35
+ "--dump-po-strings",
36
+ "--help"
37
+ ]);
38
+ if (bashLikeFlags.has(first)) {
39
+ return true;
40
+ }
41
+ if (!first.startsWith("-")) {
42
+ return first.endsWith(".sh");
43
+ }
44
+ return false;
45
+ }
46
+ export {
47
+ looksLikeShellInvocation
48
+ };
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bun
2
+ import { type AgentRuntime, type RuntimeSnapshotSidecar } from "@rig/contracts";
3
+ type AgentWrapperOptions = {
4
+ projectRoot?: string;
5
+ argv?: string[];
6
+ };
7
+ type RuntimeProvider = "pi";
8
+ type LineSink = Pick<typeof process.stdout, "write">;
9
+ type PiRpcProviderRunInput = {
10
+ readonly command: string[];
11
+ readonly cwd: string;
12
+ readonly env: Record<string, string>;
13
+ readonly prompt: string;
14
+ readonly runId?: string;
15
+ readonly sessionName?: string;
16
+ readonly stdout?: LineSink;
17
+ readonly stderr?: LineSink;
18
+ };
19
+ export declare function finalizeRuntimeSnapshot(snapshotSidecar: Pick<RuntimeSnapshotSidecar, "finalize">, providerCommand: string[], exitCode: number, context: {
20
+ runtimeId: string;
21
+ taskId: string;
22
+ }): Promise<{
23
+ ok: true;
24
+ } | {
25
+ ok: false;
26
+ snapshotMissing: true;
27
+ error: string;
28
+ }>;
29
+ export declare function startOptionalRuntimeSnapshotSidecar(runtime: AgentRuntime, startSidecar: (runtime: AgentRuntime, options?: {
30
+ instanceId?: string;
31
+ }) => Promise<RuntimeSnapshotSidecar>): Promise<RuntimeSnapshotSidecar | null>;
32
+ export declare function runAgentWrapper(options?: AgentWrapperOptions): Promise<number>;
33
+ export declare function runPiRpcProviderFallback(input: PiRpcProviderRunInput): Promise<number>;
34
+ export declare const runPiRpcProvider: typeof runPiRpcProviderFallback;
35
+ export declare function resolveFinalProviderExitCode(input: {
36
+ providerExitCode: number;
37
+ taskClosed: boolean;
38
+ serverManagedRun: boolean;
39
+ }): number;
40
+ export declare function shouldBypassProviderSandboxOnPlatform(provider: RuntimeProvider, platform: NodeJS.Platform): boolean;
41
+ /**
42
+ * Whether to run the provider command WITHOUT the outer runtime sandbox wrap.
43
+ *
44
+ * GATE-1b: an explicit `sandbox=enforce` (config `workspace.sandbox=enforce` →
45
+ * `RIG_RUNTIME_SANDBOX=enforce`) is honored on every provider/platform — it is NEVER
46
+ * silently dropped, not even on the pi/macOS path. The provider-specific bypass
47
+ * ({@link shouldBypassProviderSandboxOnPlatform}) applies ONLY when the operator has
48
+ * not explicitly demanded enforcement.
49
+ */
50
+ export declare function resolveOuterSandboxBypass(provider: RuntimeProvider, platform: NodeJS.Platform, explicitSandboxSetting: string | undefined): boolean;
51
+ export declare function buildProviderArgs(_provider: RuntimeProvider, _runtime: Pick<AgentRuntime, "binDir" | "stateDir" | "contextFile">, argv: string[]): string[];
52
+ export declare function resolveProvider(): RuntimeProvider;
53
+ export declare function isTaskClosed(projectRoot: string, taskId: string): Promise<boolean>;
54
+ export declare function recordSnapshotMissingTaskSourceEvidence(projectRoot: string, taskId: string, runtime: Pick<AgentRuntime, "workspaceDir" | "logsDir" | "sessionDir">, snapshotFinalizeError: string): Promise<void>;
55
+ export declare function resolveRuntimeHandoffPath(hostProjectRoot: string, taskId: string, timestampMs?: number): string;
56
+ export declare function recordRuntimeHandoff(hostProjectRoot: string, runtime: Pick<AgentRuntime, "id" | "mode" | "workspaceDir" | "logsDir" | "sessionDir">, taskId: string, exitCode: number, options?: {
57
+ snapshotMissing?: boolean;
58
+ snapshotFinalizeError?: string | null;
59
+ }): void;
60
+ export {};