@h-rig/runtime 0.0.6-alpha.0

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 (176) hide show
  1. package/README.md +27 -0
  2. package/dist/bin/rig-agent-dispatch.js +9615 -0
  3. package/dist/bin/rig-agent.js +9512 -0
  4. package/dist/bin/rig-browser-tool.js +269 -0
  5. package/dist/src/agent-mode.js +48 -0
  6. package/dist/src/baked-secrets.js +121 -0
  7. package/dist/src/binary-build-worker.js +312 -0
  8. package/dist/src/binary-run.js +540 -0
  9. package/dist/src/boundaries.js +1 -0
  10. package/dist/src/build-time-config.js +25 -0
  11. package/dist/src/control-plane/agent-roles.js +27 -0
  12. package/dist/src/control-plane/agent-wrapper.js +9621 -0
  13. package/dist/src/control-plane/authority-files.js +582 -0
  14. package/dist/src/control-plane/browser-contract.js +135 -0
  15. package/dist/src/control-plane/controlled-bash.js +1111 -0
  16. package/dist/src/control-plane/errors.js +13 -0
  17. package/dist/src/control-plane/harness-main.js +10828 -0
  18. package/dist/src/control-plane/hook-materializer.js +75 -0
  19. package/dist/src/control-plane/hooks/audit-trail.js +353 -0
  20. package/dist/src/control-plane/hooks/completion-verification.js +7552 -0
  21. package/dist/src/control-plane/hooks/import-guard.js +890 -0
  22. package/dist/src/control-plane/hooks/inject-context.js +4189 -0
  23. package/dist/src/control-plane/hooks/post-edit-lint.js +43 -0
  24. package/dist/src/control-plane/hooks/safety-guard.js +910 -0
  25. package/dist/src/control-plane/hooks/scope-guard.js +907 -0
  26. package/dist/src/control-plane/hooks/shared.js +44 -0
  27. package/dist/src/control-plane/hooks/submodule-branch.js +7797 -0
  28. package/dist/src/control-plane/hooks/task-runtime-start.js +7799 -0
  29. package/dist/src/control-plane/hooks/test-integrity-guard.js +891 -0
  30. package/dist/src/control-plane/materialize-task-config.js +453 -0
  31. package/dist/src/control-plane/memory-sync/cli.js +2019 -0
  32. package/dist/src/control-plane/memory-sync/db.js +753 -0
  33. package/dist/src/control-plane/memory-sync/embed.js +281 -0
  34. package/dist/src/control-plane/memory-sync/index.js +2049 -0
  35. package/dist/src/control-plane/memory-sync/query.js +294 -0
  36. package/dist/src/control-plane/memory-sync/read.js +784 -0
  37. package/dist/src/control-plane/memory-sync/types.js +6 -0
  38. package/dist/src/control-plane/memory-sync/write.js +1547 -0
  39. package/dist/src/control-plane/native/git-native.js +490 -0
  40. package/dist/src/control-plane/native/git-ops.js +2860 -0
  41. package/dist/src/control-plane/native/harness-cli.js +9721 -0
  42. package/dist/src/control-plane/native/pr-automation.js +373 -0
  43. package/dist/src/control-plane/native/profile-ops.js +481 -0
  44. package/dist/src/control-plane/native/repo-ops.js +2342 -0
  45. package/dist/src/control-plane/native/root-resolver.js +66 -0
  46. package/dist/src/control-plane/native/run-ops.js +3281 -0
  47. package/dist/src/control-plane/native/runtime-native-sidecar.js +299 -0
  48. package/dist/src/control-plane/native/runtime-native.js +392 -0
  49. package/dist/src/control-plane/native/scope-rules.js +17 -0
  50. package/dist/src/control-plane/native/task-ops.js +6320 -0
  51. package/dist/src/control-plane/native/task-state.js +1512 -0
  52. package/dist/src/control-plane/native/utils.js +535 -0
  53. package/dist/src/control-plane/native/validator-binaries.js +889 -0
  54. package/dist/src/control-plane/native/validator.js +2197 -0
  55. package/dist/src/control-plane/native/verifier.js +3249 -0
  56. package/dist/src/control-plane/native/workspace-ops.js +1635 -0
  57. package/dist/src/control-plane/plugin-host-context.js +334 -0
  58. package/dist/src/control-plane/project-main-pre-run-sync.js +630 -0
  59. package/dist/src/control-plane/provider/claude-stream-records.js +158 -0
  60. package/dist/src/control-plane/provider/codex-app-server.js +885 -0
  61. package/dist/src/control-plane/provider/codex-exec-records.js +203 -0
  62. package/dist/src/control-plane/provider/rig-task-run-skill.js +39 -0
  63. package/dist/src/control-plane/provider/runtime-instructions.js +96 -0
  64. package/dist/src/control-plane/remote.js +854 -0
  65. package/dist/src/control-plane/repos/index.js +473 -0
  66. package/dist/src/control-plane/repos/layout.js +124 -0
  67. package/dist/src/control-plane/repos/mirror/bootstrap.js +268 -0
  68. package/dist/src/control-plane/repos/mirror/refresh.js +398 -0
  69. package/dist/src/control-plane/repos/mirror/state.js +167 -0
  70. package/dist/src/control-plane/repos/registry.js +77 -0
  71. package/dist/src/control-plane/repos/types.js +1 -0
  72. package/dist/src/control-plane/runtime/agent-mode.js +48 -0
  73. package/dist/src/control-plane/runtime/baked-secrets.js +120 -0
  74. package/dist/src/control-plane/runtime/claude-tool-router-binary.js +343 -0
  75. package/dist/src/control-plane/runtime/claude-tool-router.js +520 -0
  76. package/dist/src/control-plane/runtime/context.js +216 -0
  77. package/dist/src/control-plane/runtime/events.js +218 -0
  78. package/dist/src/control-plane/runtime/guard-types.js +6 -0
  79. package/dist/src/control-plane/runtime/guard.js +880 -0
  80. package/dist/src/control-plane/runtime/image/fingerprint-sidecar.js +1194 -0
  81. package/dist/src/control-plane/runtime/image/index.js +2255 -0
  82. package/dist/src/control-plane/runtime/image-fingerprint-sidecar.js +1191 -0
  83. package/dist/src/control-plane/runtime/image.js +2255 -0
  84. package/dist/src/control-plane/runtime/index.js +8511 -0
  85. package/dist/src/control-plane/runtime/isolation/discovery.js +599 -0
  86. package/dist/src/control-plane/runtime/isolation/home.js +1217 -0
  87. package/dist/src/control-plane/runtime/isolation/index.js +8193 -0
  88. package/dist/src/control-plane/runtime/isolation/runner.js +2651 -0
  89. package/dist/src/control-plane/runtime/isolation/shared.js +501 -0
  90. package/dist/src/control-plane/runtime/isolation/toolchain.js +1892 -0
  91. package/dist/src/control-plane/runtime/isolation/types.js +1 -0
  92. package/dist/src/control-plane/runtime/isolation/worktree.js +509 -0
  93. package/dist/src/control-plane/runtime/isolation.js +8193 -0
  94. package/dist/src/control-plane/runtime/overlay.js +67 -0
  95. package/dist/src/control-plane/runtime/plugin-mode.js +41 -0
  96. package/dist/src/control-plane/runtime/plugins.js +1131 -0
  97. package/dist/src/control-plane/runtime/provisioning-env.js +220 -0
  98. package/dist/src/control-plane/runtime/queue.js +8358 -0
  99. package/dist/src/control-plane/runtime/rig-shell.js +205 -0
  100. package/dist/src/control-plane/runtime/rig-tools.js +182 -0
  101. package/dist/src/control-plane/runtime/runner-context.js +1 -0
  102. package/dist/src/control-plane/runtime/runtime-paths.js +184 -0
  103. package/dist/src/control-plane/runtime/sandbox/backend-bwrap.js +311 -0
  104. package/dist/src/control-plane/runtime/sandbox/backend-none.js +21 -0
  105. package/dist/src/control-plane/runtime/sandbox/backend-seatbelt.js +268 -0
  106. package/dist/src/control-plane/runtime/sandbox/backend.js +1718 -0
  107. package/dist/src/control-plane/runtime/sandbox/orchestrator.js +1745 -0
  108. package/dist/src/control-plane/runtime/sandbox/utils.js +137 -0
  109. package/dist/src/control-plane/runtime/sandbox-backend-bwrap.js +311 -0
  110. package/dist/src/control-plane/runtime/sandbox-backend-none.js +21 -0
  111. package/dist/src/control-plane/runtime/sandbox-backend-seatbelt.js +268 -0
  112. package/dist/src/control-plane/runtime/sandbox-backend.js +1718 -0
  113. package/dist/src/control-plane/runtime/sandbox-orchestrator.js +1745 -0
  114. package/dist/src/control-plane/runtime/sandbox-utils.js +137 -0
  115. package/dist/src/control-plane/runtime/snapshot/index.js +454 -0
  116. package/dist/src/control-plane/runtime/snapshot/sidecar.js +502 -0
  117. package/dist/src/control-plane/runtime/snapshot/task-run.js +1578 -0
  118. package/dist/src/control-plane/runtime/snapshot-sidecar.js +498 -0
  119. package/dist/src/control-plane/runtime/snapshot.js +454 -0
  120. package/dist/src/control-plane/runtime/task-run-snapshot.js +1578 -0
  121. package/dist/src/control-plane/runtime/tool-gateway.js +422 -0
  122. package/dist/src/control-plane/runtime/tooling/browser-tools.js +32 -0
  123. package/dist/src/control-plane/runtime/tooling/claude-router-binary.js +343 -0
  124. package/dist/src/control-plane/runtime/tooling/claude-router.js +524 -0
  125. package/dist/src/control-plane/runtime/tooling/file-tools.js +182 -0
  126. package/dist/src/control-plane/runtime/tooling/gateway.js +422 -0
  127. package/dist/src/control-plane/runtime/tooling/index.js +1290 -0
  128. package/dist/src/control-plane/runtime/tooling/shell.js +205 -0
  129. package/dist/src/control-plane/runtime/types.js +1 -0
  130. package/dist/src/control-plane/setup-version.js +14 -0
  131. package/dist/src/control-plane/state-sync/index.js +1509 -0
  132. package/dist/src/control-plane/state-sync/read.js +856 -0
  133. package/dist/src/control-plane/state-sync/reconcile.js +260 -0
  134. package/dist/src/control-plane/state-sync/repo.js +302 -0
  135. package/dist/src/control-plane/state-sync/types.js +111 -0
  136. package/dist/src/control-plane/state-sync/write.js +1469 -0
  137. package/dist/src/control-plane/task-fields.js +38 -0
  138. package/dist/src/control-plane/task-source-bootstrap.js +46 -0
  139. package/dist/src/control-plane/task-source.js +30 -0
  140. package/dist/src/control-plane/tasks/legacy-task-config-source.js +130 -0
  141. package/dist/src/control-plane/tasks/plugin-task-source.js +103 -0
  142. package/dist/src/control-plane/tasks/source-aware-task-config-source.js +611 -0
  143. package/dist/src/control-plane/tasks/source-lifecycle.js +1093 -0
  144. package/dist/src/control-plane/tasks/task-record-reader.js +9 -0
  145. package/dist/src/control-plane/validators/boundary/public-apis.js +107 -0
  146. package/dist/src/control-plane/validators/integration/_shared.js +51 -0
  147. package/dist/src/control-plane/validators/integration/adm-audit-http.js +85 -0
  148. package/dist/src/control-plane/validators/integration/adm-auth-http.js +78 -0
  149. package/dist/src/control-plane/validators/integration/adm-issuer-http.js +80 -0
  150. package/dist/src/control-plane/validators/integration/adm-migration.js +78 -0
  151. package/dist/src/control-plane/validators/integration/adm-scaffold.js +78 -0
  152. package/dist/src/control-plane/validators/runtime-registration.js +64 -0
  153. package/dist/src/control-plane/validators/shared.js +683 -0
  154. package/dist/src/events.js +218 -0
  155. package/dist/src/execution.js +35 -0
  156. package/dist/src/index.js +1633 -0
  157. package/dist/src/layout.js +145 -0
  158. package/dist/src/local-server.js +202 -0
  159. package/dist/src/plugins.js +329 -0
  160. package/dist/src/remote-http.js +83 -0
  161. package/dist/src/runtime-context.js +216 -0
  162. package/dist/src/types.js +1 -0
  163. package/native/darwin-arm64/bin/rig-git +0 -0
  164. package/native/darwin-arm64/bin/rig-shell +0 -0
  165. package/native/darwin-arm64/bin/rig-tools +0 -0
  166. package/native/darwin-arm64/lib/runtime-native-darwin-arm64.dylib +0 -0
  167. package/native/darwin-arm64/lib/runtime-native.dylib +0 -0
  168. package/native/darwin-arm64/manifest.json +1 -0
  169. package/native/linux-x64/bin/rig-git +0 -0
  170. package/native/linux-x64/bin/rig-shell +0 -0
  171. package/native/linux-x64/bin/rig-tools +0 -0
  172. package/native/linux-x64/lib/runtime-native-linux-x64.so +0 -0
  173. package/native/linux-x64/lib/runtime-native.so +0 -0
  174. package/native/linux-x64/manifest.json +1 -0
  175. package/package.json +74 -0
  176. package/skills/rig-task-run.md +71 -0
@@ -0,0 +1,203 @@
1
+ // @bun
2
+ // packages/runtime/src/control-plane/provider/codex-exec-records.ts
3
+ function asRecord(value) {
4
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
5
+ }
6
+ function normalizeString(value) {
7
+ if (typeof value !== "string") {
8
+ return null;
9
+ }
10
+ const trimmed = value.trim();
11
+ return trimmed.length > 0 ? trimmed : null;
12
+ }
13
+ function normalizeIsoTimestamp(value) {
14
+ const normalized = normalizeString(value);
15
+ if (!normalized) {
16
+ return null;
17
+ }
18
+ const timestamp = Date.parse(normalized);
19
+ return Number.isNaN(timestamp) ? null : new Date(timestamp).toISOString();
20
+ }
21
+ function isCodexExecRecord(record) {
22
+ const type = normalizeString(record.type);
23
+ return type === "thread.started" || type === "thread.completed" || type === "turn.started" || type === "turn.completed" || type === "item.started" || type === "item.completed";
24
+ }
25
+ function extractCodexAssistantMessageText(record) {
26
+ if (normalizeString(record.type) !== "item.completed") {
27
+ return null;
28
+ }
29
+ const item = asRecord(record.item);
30
+ if (!item || normalizeString(item.type) !== "agent_message") {
31
+ return null;
32
+ }
33
+ return normalizeString(item.text);
34
+ }
35
+ function codexToolName(itemType, item) {
36
+ if (itemType === "command_execution") {
37
+ return "Bash";
38
+ }
39
+ const server = normalizeString(item.server);
40
+ const tool = normalizeString(item.tool);
41
+ if (server && tool) {
42
+ return `mcp__${server}__${tool}`;
43
+ }
44
+ return tool;
45
+ }
46
+ function codexToolInput(itemType, item) {
47
+ if (itemType === "command_execution") {
48
+ return {
49
+ command: normalizeString(item.command)
50
+ };
51
+ }
52
+ return item.arguments ?? item.input ?? null;
53
+ }
54
+ function codexToolResult(itemType, item) {
55
+ if (itemType === "command_execution") {
56
+ return {
57
+ command: normalizeString(item.command),
58
+ stdout: normalizeString(item.aggregated_output),
59
+ exit_code: typeof item.exit_code === "number" ? item.exit_code : null,
60
+ status: normalizeString(item.status)
61
+ };
62
+ }
63
+ const error = asRecord(item.error);
64
+ if (error) {
65
+ return {
66
+ content: normalizeString(error.message) ?? JSON.stringify(error),
67
+ error
68
+ };
69
+ }
70
+ return item.result ?? item.output ?? item;
71
+ }
72
+ function codexToolError(itemType, item) {
73
+ if (itemType === "command_execution") {
74
+ return typeof item.exit_code === "number" && item.exit_code !== 0 || normalizeString(item.status) === "failed";
75
+ }
76
+ return item.error != null || normalizeString(item.status) === "failed";
77
+ }
78
+ function buildCodexLogsFromRecord(input) {
79
+ const entryType = normalizeString(input.record.type);
80
+ if (entryType !== "item.started" && entryType !== "item.completed") {
81
+ return [];
82
+ }
83
+ const item = asRecord(input.record.item);
84
+ if (!item) {
85
+ return [];
86
+ }
87
+ const itemTypeRaw = normalizeString(item.type);
88
+ const itemType = itemTypeRaw === "command_execution" || itemTypeRaw === "mcp_tool_call" ? itemTypeRaw : null;
89
+ const createdAt = normalizeIsoTimestamp(input.record.timestamp) ?? input.createdAtFallback;
90
+ if (!itemType) {
91
+ if (itemTypeRaw === "agent_message" && input.includeMessageLogs) {
92
+ const text = normalizeString(item.text);
93
+ if (!text) {
94
+ return [];
95
+ }
96
+ return [{
97
+ id: normalizeString(item.id) ?? `${input.runId}-codex-message-${Date.now()}`,
98
+ runId: input.runId,
99
+ title: "Assistant output",
100
+ detail: JSON.stringify({
101
+ type: "assistant",
102
+ message: {
103
+ role: "assistant",
104
+ content: [{ type: "text", text }]
105
+ }
106
+ }),
107
+ tone: "info",
108
+ status: input.status,
109
+ payload: { text },
110
+ createdAt
111
+ }];
112
+ }
113
+ return [];
114
+ }
115
+ const itemId = normalizeString(item.id);
116
+ if (!itemId) {
117
+ return [];
118
+ }
119
+ if (entryType === "item.started") {
120
+ input.pendingToolUses.set(itemId, {
121
+ id: itemId,
122
+ itemType,
123
+ name: codexToolName(itemType, item),
124
+ input: codexToolInput(itemType, item),
125
+ timestamp: createdAt,
126
+ record: item
127
+ });
128
+ return [];
129
+ }
130
+ const pending = input.pendingToolUses.get(itemId) ?? null;
131
+ if (pending) {
132
+ input.pendingToolUses.delete(itemId);
133
+ }
134
+ const toolName = pending?.name ?? codexToolName(itemType, item);
135
+ const toolInput = pending?.input ?? codexToolInput(itemType, item);
136
+ const toolResult = codexToolResult(itemType, item);
137
+ const isError = codexToolError(itemType, item);
138
+ const stdout = asRecord(toolResult)?.stdout;
139
+ return [{
140
+ id: `${input.runId}-codex-tool-${itemId}`,
141
+ runId: input.runId,
142
+ title: "Tool activity",
143
+ detail: JSON.stringify({
144
+ type: "agent_tool_activity",
145
+ provider: "codex",
146
+ item_type: itemType,
147
+ tool_use_id: itemId,
148
+ tool_name: toolName,
149
+ tool_input: toolInput,
150
+ tool_result: toolResult,
151
+ is_error: isError,
152
+ raw: {
153
+ started: pending?.record ?? null,
154
+ completed: item
155
+ }
156
+ }),
157
+ tone: isError ? "error" : "tool",
158
+ status: input.status,
159
+ payload: {
160
+ toolUseId: itemId,
161
+ toolName,
162
+ toolInput,
163
+ content: typeof stdout === "string" ? stdout : null,
164
+ isError
165
+ },
166
+ createdAt: pending?.timestamp ?? createdAt
167
+ }];
168
+ }
169
+ function flushPendingCodexToolUseLogs(input) {
170
+ const logs = [];
171
+ for (const pending of input.pendingToolUses.values()) {
172
+ logs.push({
173
+ id: `${input.runId}-codex-tool-${pending.id}`,
174
+ runId: input.runId,
175
+ title: "Tool activity",
176
+ detail: JSON.stringify({
177
+ type: "agent_tool_use",
178
+ provider: "codex",
179
+ item_type: pending.itemType,
180
+ tool_use_id: pending.id,
181
+ tool_name: pending.name,
182
+ tool_input: pending.input,
183
+ raw: pending.record
184
+ }),
185
+ tone: "tool",
186
+ status: input.status,
187
+ payload: {
188
+ toolUseId: pending.id,
189
+ toolName: pending.name,
190
+ toolInput: pending.input
191
+ },
192
+ createdAt: pending.timestamp
193
+ });
194
+ }
195
+ input.pendingToolUses.clear();
196
+ return logs;
197
+ }
198
+ export {
199
+ isCodexExecRecord,
200
+ flushPendingCodexToolUseLogs,
201
+ extractCodexAssistantMessageText,
202
+ buildCodexLogsFromRecord
203
+ };
@@ -0,0 +1,39 @@
1
+ // @bun
2
+ // packages/runtime/src/control-plane/provider/rig-task-run-skill.ts
3
+ import { existsSync, readFileSync } from "fs";
4
+ import { dirname, resolve } from "path";
5
+ import { fileURLToPath } from "url";
6
+ var SKILL_FILENAME = "rig-task-run.md";
7
+ var FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
8
+ var cachedBody = null;
9
+ function loadRigTaskRunSkillBody() {
10
+ if (cachedBody !== null) {
11
+ return cachedBody;
12
+ }
13
+ const path = resolveSkillPath();
14
+ if (!path) {
15
+ cachedBody = "";
16
+ return cachedBody;
17
+ }
18
+ const raw = readFileSync(path, "utf-8");
19
+ const match = raw.match(FRONTMATTER_RE);
20
+ cachedBody = (match ? match[2] ?? raw : raw).trim();
21
+ return cachedBody;
22
+ }
23
+ function resolveSkillPath() {
24
+ const here = dirname(fileURLToPath(import.meta.url));
25
+ const candidates = [
26
+ resolve(here, "..", "..", "..", "skills", SKILL_FILENAME),
27
+ resolve(here, "..", "..", "skills", SKILL_FILENAME),
28
+ resolve(here, "..", "skills", SKILL_FILENAME)
29
+ ];
30
+ for (const candidate of candidates) {
31
+ if (existsSync(candidate)) {
32
+ return candidate;
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+ export {
38
+ loadRigTaskRunSkillBody
39
+ };
@@ -0,0 +1,96 @@
1
+ // @bun
2
+ // packages/runtime/src/control-plane/provider/runtime-instructions.ts
3
+ var CLAUDE_ROUTER_TOOL_NAMES = [
4
+ "`mcp__rig_runtime_tools__read`",
5
+ "`mcp__rig_runtime_tools__write`",
6
+ "`mcp__rig_runtime_tools__edit`",
7
+ "`mcp__rig_runtime_tools__glob`",
8
+ "`mcp__rig_runtime_tools__grep`"
9
+ ].join(", ");
10
+ var CODEX_DYNAMIC_TOOL_NAMES = [
11
+ "`shell`",
12
+ "`read`",
13
+ "`write`",
14
+ "`edit`",
15
+ "`glob`",
16
+ "`grep`"
17
+ ].join(", ");
18
+ function normalizeRuntimeInstructionProvider(value) {
19
+ const normalized = value?.trim().toLowerCase();
20
+ if (normalized === "codex" || normalized === "codex-cli" || normalized === "codex-app-server" || normalized === "gpt-codex") {
21
+ return "codex";
22
+ }
23
+ if (normalized === "pi" || normalized === "rig-pi" || normalized === "@rig/pi") {
24
+ return "pi";
25
+ }
26
+ return "claude-code";
27
+ }
28
+ function buildProviderTaskRunInstructionLines(provider) {
29
+ if (provider === "codex") {
30
+ return [
31
+ `Use the Rig-owned dynamic tools instead: ${CODEX_DYNAMIC_TOOL_NAMES}.`,
32
+ "Those file tools can read and search within the task worktree, `$PROJECT_RIG_ROOT`, and `$MONOREPO_MAIN_ROOT`, but `write` and `edit` stay restricted to the scoped task workspace.",
33
+ "Codex shell work must go through the Rig-owned `shell` tool, which executes through Rig's gatewayed binaries.",
34
+ "When you need shell access, call `shell` with a narrow `command` and an optional workspace-relative `workdir`.",
35
+ "Do not invoke absolute host shell paths like `/bin/bash`, `/bin/zsh`, `/usr/bin/env`, or `/usr/bin/git`.",
36
+ "Parallel Rig tool calls are supported when each call stays scoped and bounded.",
37
+ "Prefer `read` / `write` / `edit` / `glob` / `grep` over shell one-liners whenever those tools fit.",
38
+ "Never run repo-wide `rg` or `grep` against `.` or without an explicit narrow path; start with a scoped router `glob`/`grep`, `rg --files <dir>`, or pipe through `head` before widening."
39
+ ];
40
+ }
41
+ if (provider === "pi") {
42
+ return [
43
+ "Use Pi's built-in `read`, `write`, `edit`, and `bash` tools from the isolated Rig task worktree.",
44
+ "Keep file writes inside the scoped task workspace unless Rig explicitly tells you a path is host/project metadata.",
45
+ "Prefer `read`, `write`, and `edit` over shell one-liners whenever those tools fit.",
46
+ "When shell access is needed, keep commands narrow and bounded; avoid repo-wide searches without an explicit path and output cap."
47
+ ];
48
+ }
49
+ return [
50
+ "Claude's built-in `Read`, `Edit`, `Write`, `Glob`, `Grep`, and `NotebookEdit` tools are disabled for this task runtime.",
51
+ `Use the Rig-owned file tools exposed by the runtime router instead: ${CLAUDE_ROUTER_TOOL_NAMES}.`,
52
+ "Those file tools can read and search within the task worktree, `$PROJECT_RIG_ROOT`, and `$MONOREPO_MAIN_ROOT`, but `write` and `edit` stay restricted to the scoped task workspace.",
53
+ "Use `.rig/bin/bash` or `.rig/bin/sh` only for shell work that is not naturally a file-tool operation.",
54
+ "Do not issue parallel Bash tool calls. Run shell commands serially; Claude Code's parallel Bash mode can lose cwd state inside the isolated worktree."
55
+ ];
56
+ }
57
+ function buildProviderRuntimeContextLines(provider) {
58
+ if (provider === "codex") {
59
+ return [
60
+ "Codex file and shell work must go through Rig-owned dynamic tools.",
61
+ `Use the dynamic tools instead: ${CODEX_DYNAMIC_TOOL_NAMES}.`,
62
+ "`read`/`glob`/`grep` may inspect the task worktree, `$PROJECT_RIG_ROOT`, and `$MONOREPO_MAIN_ROOT`.",
63
+ "`write` and `edit` remain restricted to the scoped task workspace.",
64
+ "Codex shell work must stay inside Rig's gatewayed binaries via the `shell` tool.",
65
+ "Do not invoke absolute host shell paths like `/bin/bash`, `/bin/zsh`, `/usr/bin/env`, or `/usr/bin/git`.",
66
+ "Parallel Rig tool calls are supported when each call stays scoped and bounded.",
67
+ "Never run repo-wide `rg` or `grep` against `.` or without an explicit narrow path; start with a scoped router `glob`/`grep`, `rg --files <dir>`, or pipe through `head` before widening."
68
+ ];
69
+ }
70
+ if (provider === "pi") {
71
+ return [
72
+ "Pi runs from the isolated Rig task worktree with its built-in `read`, `write`, `edit`, and `bash` tools enabled.",
73
+ "Keep writes scoped to the task workspace unless Rig-provided instructions name an explicit metadata path.",
74
+ "Prefer Pi file tools over shell one-liners for file reads and edits.",
75
+ "Keep shell commands narrow and bounded; cap broad searches before widening."
76
+ ];
77
+ }
78
+ return [
79
+ "Claude's built-in Read/Edit/Write/Glob/Grep/NotebookEdit tools are disabled in this runtime.",
80
+ "Use the Rig-owned router tools instead:",
81
+ "`read`/`glob`/`grep` may inspect the task worktree, `$PROJECT_RIG_ROOT`, and `$MONOREPO_MAIN_ROOT`.",
82
+ "`write` and `edit` remain restricted to the scoped task workspace.",
83
+ "mcp__rig_runtime_tools__read",
84
+ "mcp__rig_runtime_tools__write",
85
+ "mcp__rig_runtime_tools__edit",
86
+ "mcp__rig_runtime_tools__glob",
87
+ "mcp__rig_runtime_tools__grep",
88
+ "Use `.rig/bin/bash` or `.rig/bin/sh` only for shell-oriented work.",
89
+ "Run shell commands serially; parallel Bash calls can lose cwd state inside the isolated worktree."
90
+ ];
91
+ }
92
+ export {
93
+ normalizeRuntimeInstructionProvider,
94
+ buildProviderTaskRunInstructionLines,
95
+ buildProviderRuntimeContextLines
96
+ };