@mnaimfaizy/agent-kit 1.0.0-beta.13 → 1.0.0-beta.15

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 (79) hide show
  1. package/README.md +24 -5
  2. package/custom-harness.schema.json +243 -0
  3. package/harnesses.json +286 -0
  4. package/package.json +4 -2
  5. package/src/checks/ci-workflow.mjs +105 -0
  6. package/src/checks/claude-app.mjs +11 -2
  7. package/src/checks/custom-harness.mjs +157 -0
  8. package/src/checks/github-app.mjs +214 -0
  9. package/src/checks/review-response.mjs +54 -27
  10. package/src/checks/rulesets.mjs +9 -8
  11. package/src/checks/secrets-and-variables.mjs +220 -43
  12. package/src/checks/stages.mjs +705 -0
  13. package/src/cli.mjs +277 -31
  14. package/src/deep-scan/agent.mjs +145 -117
  15. package/src/deep-scan/credential.mjs +88 -42
  16. package/src/deep-scan/docker-driver.mjs +131 -49
  17. package/src/deep-scan/harness-text.mjs +99 -0
  18. package/src/deep-scan/lifecycle.mjs +92 -199
  19. package/src/deep-scan/limits.mjs +13 -7
  20. package/src/deep-scan/model-proxy.mjs +47 -602
  21. package/src/deep-scan/preflight.mjs +81 -1
  22. package/src/deep-scan/recipe.mjs +7 -7
  23. package/src/deep-scan/runtime.mjs +54 -6
  24. package/src/deep-scan/sandbox-run.mjs +232 -0
  25. package/src/deep-scan/sbx-driver.mjs +242 -50
  26. package/src/deep-scan/tar.mjs +69 -22
  27. package/src/deep-scan/verify.mjs +6 -1
  28. package/src/deep-scan.mjs +98 -14
  29. package/src/doctor.mjs +113 -4
  30. package/src/harness/adapters.mjs +30 -0
  31. package/src/harness/antigravity.mjs +187 -0
  32. package/src/harness/claude-code.mjs +236 -0
  33. package/src/harness/codex.mjs +219 -0
  34. package/src/harness/cursor.mjs +199 -0
  35. package/src/harness/custom/registry.mjs +21 -0
  36. package/src/harness/custom/schema.mjs +90 -0
  37. package/src/harness/custom.mjs +299 -0
  38. package/src/harness/facts.mjs +157 -0
  39. package/src/harness/gemini.mjs +164 -0
  40. package/src/harness/install-layer.mjs +141 -0
  41. package/src/harness/opencode.mjs +289 -0
  42. package/src/harness/resolve.mjs +156 -0
  43. package/src/harness/support-levels.mjs +197 -0
  44. package/src/harness-live/assess.mjs +291 -0
  45. package/src/harness-live/cursor-real.mjs +146 -0
  46. package/src/harness-live/cursor-version.mjs +70 -0
  47. package/src/harness-live/cursor.mjs +80 -0
  48. package/src/harness-live/custom.mjs +91 -0
  49. package/src/harness-live/fixture-harness.mjs +45 -0
  50. package/src/harness-live/harnesses.mjs +263 -0
  51. package/src/harness-live/host.mjs +414 -0
  52. package/src/harness-live/opencode.mjs +289 -0
  53. package/src/harness-live/probes.mjs +239 -0
  54. package/src/harness-live/run.mjs +214 -0
  55. package/src/harness-live/setup.mjs +126 -0
  56. package/src/harness-live/stage.mjs +161 -0
  57. package/src/harness-live/suite.mjs +481 -0
  58. package/src/harness-test.mjs +116 -0
  59. package/src/init.mjs +339 -23
  60. package/src/model-proxy/core.mjs +657 -0
  61. package/src/model-proxy/profiles/anthropic.mjs +241 -0
  62. package/src/model-proxy/profiles/gemini-api.mjs +311 -0
  63. package/src/model-proxy/profiles/openai.mjs +327 -0
  64. package/src/model-proxy/stub-dialects/anthropic.mjs +110 -0
  65. package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
  66. package/src/model-proxy/stub-dialects/openai.mjs +173 -0
  67. package/src/model-proxy/stub.mjs +182 -0
  68. package/src/stage/audit.mjs +79 -0
  69. package/src/stage/egress-route.mjs +207 -0
  70. package/src/stage/implement/carry.mjs +308 -0
  71. package/src/stage/implement/sandbox.mjs +271 -0
  72. package/src/stage/implement/verify.mjs +70 -0
  73. package/src/stage/implement.mjs +218 -0
  74. package/src/stage/plan.mjs +115 -0
  75. package/src/stage/review-response.mjs +172 -0
  76. package/src/stage/review.mjs +185 -0
  77. package/src/stage/workspace.mjs +274 -0
  78. package/src/stage.mjs +1068 -0
  79. package/src/deep-scan/claude-code.mjs +0 -25
@@ -0,0 +1,236 @@
1
+ // The Claude Code Harness adapter (ADR 0027): one function that takes a
2
+ // Stage request and returns a launch plan, as plain data. The Launcher does
3
+ // everything with the plan; this module starts nothing and imports nothing.
4
+ //
5
+ // The CLI: one pinned version, in `/opt/agent-kit` of the kit's Harness image
6
+ // (ADR 0029, docker/harness-images/), which is pinned by digest, with the
7
+ // auto-updater off both by environment and by managed settings in
8
+ // /etc/claude-code, which the repository's own project settings cannot
9
+ // override. Nothing is installed at run time.
10
+ //
11
+ // The launch: print mode, the brief on stdin. `--bare` skips skill and
12
+ // CLAUDE.md discovery, so the Launcher hands the agent everything
13
+ // explicitly, in its brief. The agent holds only the run's caller key as its
14
+ // API key. Its model API base URL is pinned by the Launcher's own `--settings`, which
15
+ // outrank project settings, and project and local settings are not even
16
+ // loaded (`--setting-sources user`), so the scanned repository's
17
+ // `.claude/settings.json` cannot point it elsewhere. Web tools are not in
18
+ // its tool set, and are denied as well. Its turn limit is `--max-turns` on
19
+ // the command line (#371).
20
+ //
21
+ // On the subscription path (#375) it holds the caller key as its
22
+ // CLAUDE_CODE_OAUTH_TOKEN instead, and runs without `--bare`, which never
23
+ // reads one. So it can discover the scanned repository's CLAUDE.md and
24
+ // skills: the brief says they are that repository's content, and that its
25
+ // own procedure decides. The settings stay pinned the same way, hooks are
26
+ // off in them, and `--strict-mcp-config` keeps any MCP server the
27
+ // repository names from starting.
28
+
29
+ /** The Claude Code version every sandbox runs, pinned. */
30
+ const VERSION = "2.1.328";
31
+
32
+ /**
33
+ * The Harness image that holds that version. The `harness-images` workflow
34
+ * builds it in the pull request that changes the pin or its Dockerfile, and
35
+ * fails until this holds the digest it pushed
36
+ * (`node docker/harness-images/image.mjs record claude-code`).
37
+ */
38
+ const IMAGE = "ghcr.io/mnaimfaizy/agent-kit-sandbox-claude-code";
39
+ const IMAGE_DIGEST = "sha256:076c453ea2c86191e20e0c66d717c886dffda18549f1df2e6fdc0630d48e9a5f"; // inputs-bbd92fca1095d0aa25d8c7b8d963b90d
40
+
41
+ /** The environment that keeps the auto-updater off. */
42
+ const AUTO_UPDATER_OFF = "DISABLE_AUTOUPDATER=1";
43
+
44
+ const MANAGED_SETTINGS = JSON.stringify({ env: { DISABLE_AUTOUPDATER: "1" } });
45
+
46
+ /**
47
+ * What a Consumer needs to know about Claude Code, which `cli/harnesses.json`
48
+ * publishes per tag (ADR 0030): the kit secrets it accepts, the preferred one
49
+ * first, each with where to get it; the effort levels `--effort` takes at the
50
+ * pinned version (its --help); and the model a Stage gets when none is named.
51
+ */
52
+ export const FACTS = Object.freeze({
53
+ displayName: "Claude Code",
54
+ secrets: Object.freeze([
55
+ {
56
+ name: "claude_code_oauth_token",
57
+ whereToGet:
58
+ "Run `claude setup-token` on your machine, signed in to your Claude subscription, and paste the token.",
59
+ },
60
+ {
61
+ name: "anthropic_api_key",
62
+ whereToGet:
63
+ "Create an API key in the Anthropic Console: https://console.anthropic.com/settings/keys.",
64
+ },
65
+ ]),
66
+ effortValues: Object.freeze(["low", "medium", "high", "xhigh", "max"]),
67
+ defaultModel: "claude-opus-5-5",
68
+ });
69
+
70
+ /** The tools the agent has; the web tools are not among them. */
71
+ export const TOOLS = Object.freeze(["Bash", "Read", "Write", "Edit", "Glob", "Grep"]);
72
+ export const WEB_TOOLS = Object.freeze(["WebFetch", "WebSearch"]);
73
+
74
+ /**
75
+ * The credentials Claude Code accepts, by kind: the kit secret, the
76
+ * variable it reads in the sandbox, and the placeholder it holds there,
77
+ * which the model proxy swaps. A run with a caller key holds that instead,
78
+ * made by the Launcher to start with this placeholder. The subscription one
79
+ * is shaped like a token, in case Claude Code checks the prefix.
80
+ */
81
+ const CREDENTIALS = {
82
+ "api-key": {
83
+ secret: "anthropic_api_key",
84
+ env: "ANTHROPIC_API_KEY",
85
+ placeholder: "agent-kit-deep-scan-placeholder",
86
+ },
87
+ subscription: {
88
+ secret: "claude_code_oauth_token",
89
+ env: "CLAUDE_CODE_OAUTH_TOKEN",
90
+ placeholder: "sk-ant-oat01-agent-kit-deep-scan-placeholder",
91
+ },
92
+ };
93
+
94
+ /**
95
+ * @typedef {{
96
+ * stage?: string,
97
+ * model?: string,
98
+ * effort?: string,
99
+ * credentialKind?: "api-key" | "subscription",
100
+ * proxyUrl?: string,
101
+ * briefPath?: string,
102
+ * kitDir?: string,
103
+ * maxTurns?: number,
104
+ * callerKey?: string,
105
+ * }} StageRequest `model` and `effort` pass through verbatim, already
106
+ * checked by the Launcher; without either, Claude Code runs on its own
107
+ * default. `proxyUrl` is the model proxy as the sandbox reaches it,
108
+ * `kitDir` the Launcher's folder there, outside the workspace, and
109
+ * `maxTurns` the turn limit. `callerKey` is the run's caller key, which the
110
+ * model proxy requires: it is the chosen kind's placeholder in the plan, and
111
+ * so what the sandbox holds. A request without them (before the sandbox
112
+ * exists) gets a plan whose launch leaves them out.
113
+ *
114
+ * @typedef {{
115
+ * identity: { name: string, displayName: string, version: string, major: number },
116
+ * installLayer: { image: string, env: string[], run: string[] },
117
+ * modelRoute: { profile: string },
118
+ * credentials: {
119
+ * accepted: Record<string, { secret: string, env: string, placeholder: string }>,
120
+ * scrub: string[],
121
+ * },
122
+ * launch: {
123
+ * argv: string[],
124
+ * stdin: { file: string | undefined } | null,
125
+ * files: Array<{ path: string, text: string }>,
126
+ * env: string[],
127
+ * },
128
+ * checkoutConfig: string[],
129
+ * instructionFiles: string[],
130
+ * stops: { turnCap: { stderrPattern: string } | null },
131
+ * transcript: { path: string },
132
+ * }} LaunchPlan The nine parts of ADR 0027. `installLayer.image` is the
133
+ * Harness image, by digest: the sandbox runs from it, or its
134
+ * `/opt/agent-kit` is copied onto another glibc image, where `env` is set
135
+ * and `run`, the lines of one shell command, puts the CLI on the path.
136
+ * `credentials.scrub` names every variable a model credential of this
137
+ * harness can sit in, removed from the Launcher's own commands.
138
+ */
139
+
140
+ /**
141
+ * The launch plan for `request`.
142
+ * @param {StageRequest} [request]
143
+ * @returns {LaunchPlan}
144
+ */
145
+ export function claudeCode({
146
+ model,
147
+ effort,
148
+ credentialKind = "api-key",
149
+ proxyUrl,
150
+ briefPath,
151
+ kitDir,
152
+ maxTurns,
153
+ callerKey,
154
+ } = {}) {
155
+ const subscription = credentialKind === "subscription";
156
+ const accepted = structuredClone(CREDENTIALS);
157
+ const credential = accepted[credentialKind];
158
+ if (callerKey !== undefined) credential.placeholder = callerKey;
159
+ // The Launcher's own settings. Hooks are off where no `--bare` skips
160
+ // them: a setup step could have written some into the user settings.
161
+ const settings = {
162
+ env: {
163
+ ANTHROPIC_BASE_URL: proxyUrl,
164
+ CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
165
+ DISABLE_AUTOUPDATER: "1",
166
+ },
167
+ permissions: { allow: [...TOOLS], deny: [...WEB_TOOLS] },
168
+ ...(subscription ? { disableAllHooks: true } : {}),
169
+ };
170
+ return {
171
+ identity: { name: "claude-code", displayName: "Claude Code", version: VERSION, major: 2 },
172
+ installLayer: {
173
+ image: `${IMAGE}@${IMAGE_DIGEST}`,
174
+ env: [AUTO_UPDATER_OFF],
175
+ run: [
176
+ "ln -sf /opt/agent-kit/bin/claude /usr/local/bin/claude \\",
177
+ " && mkdir -p /etc/claude-code \\",
178
+ ` && printf '%s\\n' '${MANAGED_SETTINGS}' > /etc/claude-code/managed-settings.json`,
179
+ ],
180
+ },
181
+ modelRoute: { profile: "anthropic" },
182
+ credentials: {
183
+ accepted,
184
+ scrub: ["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "CLAUDE_CODE_OAUTH_TOKEN"],
185
+ },
186
+ launch: {
187
+ argv: [
188
+ "claude",
189
+ ...(subscription ? [] : ["--bare"]),
190
+ "--print",
191
+ "--settings",
192
+ JSON.stringify(settings),
193
+ "--setting-sources",
194
+ "user",
195
+ ...(subscription ? ["--strict-mcp-config"] : []),
196
+ "--tools",
197
+ TOOLS.join(","),
198
+ "--allowedTools",
199
+ TOOLS.join(","),
200
+ "--disallowedTools",
201
+ WEB_TOOLS.join(","),
202
+ "--permission-mode",
203
+ "dontAsk",
204
+ ...(kitDir !== undefined ? ["--add-dir", kitDir] : []),
205
+ "--no-session-persistence",
206
+ ...(maxTurns !== undefined ? ["--max-turns", String(maxTurns)] : []),
207
+ ...(model !== undefined ? ["--model", model] : []),
208
+ ...(effort !== undefined ? ["--effort", effort] : []),
209
+ ],
210
+ stdin: briefPath !== undefined ? { file: briefPath } : null,
211
+ files: [],
212
+ // The credential's variable alone: on the subscription path an API key
213
+ // would outrank the token in Claude Code's auth order.
214
+ env: [
215
+ `${credential.env}=${credential.placeholder}`,
216
+ "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1",
217
+ ],
218
+ },
219
+ // The checkout's executable harness config, and what Claude Code loads by
220
+ // itself. Declared for the Launcher; the Deep scan keeps the config from
221
+ // loading by the flags above, and removes nothing from the copy.
222
+ checkoutConfig: [".claude/settings.json", ".claude/settings.local.json", ".mcp.json"],
223
+ instructionFiles: [
224
+ "CLAUDE.md",
225
+ "CLAUDE.local.md",
226
+ ".claude/rules",
227
+ ".claude/skills",
228
+ ".claude/agents",
229
+ ".claude/commands",
230
+ ],
231
+ // Print mode says "Error: Reached max turns" on its error output.
232
+ stops: { turnCap: { stderrPattern: "^Error: Reached max turns" } },
233
+ // Where the Launcher keeps Claude Code's own output.
234
+ transcript: { path: `${kitDir ?? "/agent-kit"}/logs/agent.log` },
235
+ };
236
+ }
@@ -0,0 +1,219 @@
1
+ // The Codex CLI Harness adapter (ADR 0027): one function that takes a Stage
2
+ // request and returns a launch plan, as plain data. The Launcher does
3
+ // everything with the plan; this module starts nothing and imports nothing.
4
+ //
5
+ // The CLI: one pinned version, in `/opt/agent-kit` of the kit's Harness image
6
+ // (ADR 0029, docker/harness-images/), which is pinned by digest, with the
7
+ // update check off both in the Launcher's own config and in /etc/codex.
8
+ // Nothing is installed at run time.
9
+ //
10
+ // The launch: `codex exec`, the brief on stdin, with approvals and Codex's
11
+ // own sandbox off, since the Launcher's sandbox reaches the Guards. Codex
12
+ // reads one config file, the Launcher's, from a `CODEX_HOME` of the
13
+ // Launcher's own outside the workspace. It names a model provider of the
14
+ // kit's whose base URL is the model proxy, with WebSockets off, so every
15
+ // model request is one the `openai` provider profile judges. Web search and
16
+ // every feature that reaches outside the sandbox (apps, plugins, image
17
+ // generation, browsers), hooks, analytics, feedback and the update check are
18
+ // off. The checkout's own Codex config is removed from the copy and its
19
+ // project is marked untrusted, and no `AGENTS.md` is loaded
20
+ // (`project_doc_max_bytes = 0`): as on the Claude Code path, the brief hands
21
+ // the agent everything. `--strict-config` fails a pin that no longer knows
22
+ // one of these settings.
23
+ //
24
+ // The agent holds only the run's caller key as its `OPENAI_API_KEY`. Codex
25
+ // CLI has no turn limit, so the wall clock and the proxy's token cap bound it.
26
+
27
+ /** The Codex CLI version every sandbox runs, pinned. */
28
+ const VERSION = "0.172.0";
29
+
30
+ /**
31
+ * The Harness image that holds that version. The `harness-images` workflow
32
+ * builds it in the pull request that changes the pin or its Dockerfile, and
33
+ * fails until this holds the digest it pushed
34
+ * (`node docker/harness-images/image.mjs record codex`).
35
+ */
36
+ const IMAGE = "ghcr.io/mnaimfaizy/agent-kit-sandbox-codex";
37
+ const IMAGE_DIGEST = "sha256:987c3c106226b35afdce2c9ce983253718623c56843c7b362196516ac966a2e3"; // inputs-070b8818f9d8f4a50bd20b9db465686c
38
+
39
+ /** The system config line that keeps the update check off on any image. */
40
+ const UPDATE_CHECK_OFF = "check_for_update_on_startup = false";
41
+
42
+ /**
43
+ * What a Consumer needs to know about Codex CLI, which `cli/harnesses.json`
44
+ * publishes per tag (ADR 0030): the kit secret it accepts, with where to get
45
+ * it; the reasoning efforts its default model takes at the pinned version
46
+ * (`codex debug models --bundled`); and the model a Stage gets when none is
47
+ * named, which is the pinned version's own default.
48
+ */
49
+ export const FACTS = Object.freeze({
50
+ displayName: "Codex CLI",
51
+ secrets: Object.freeze([
52
+ {
53
+ name: "openai_api_key",
54
+ whereToGet:
55
+ "Create an API key in the OpenAI platform, in a project with its own budget: https://platform.openai.com/api-keys.",
56
+ },
57
+ ]),
58
+ effortValues: Object.freeze(["low", "medium", "high", "xhigh", "max", "ultra"]),
59
+ defaultModel: "gpt-6.2-sol",
60
+ });
61
+
62
+ /** The name of the kit's model provider in Codex's config. */
63
+ const PROVIDER = "agent-kit";
64
+
65
+ /**
66
+ * Every Codex feature switched off: what reaches outside the sandbox, what
67
+ * runs a config's own commands, and what the model proxy would refuse (a
68
+ * compressed request, a connection retried without end).
69
+ */
70
+ export const FEATURES_OFF = Object.freeze([
71
+ "apps",
72
+ "browser_use",
73
+ "browser_use_external",
74
+ "browser_use_full_cdp_access",
75
+ "computer_use",
76
+ "daemon_auto_start",
77
+ "enable_request_compression",
78
+ "hooks",
79
+ "image_generation",
80
+ "in_app_browser",
81
+ "plugin_sharing",
82
+ "plugins",
83
+ "remote_plugin",
84
+ "shell_snapshot",
85
+ "skill_mcp_dependency_install",
86
+ "tool_suggest",
87
+ "unbounded_connection_retries",
88
+ "workspace_dependencies",
89
+ ]);
90
+
91
+ /**
92
+ * The credential Codex CLI accepts: the kit secret, the variable it reads in
93
+ * the sandbox, and the placeholder it holds there, which the model proxy swaps.
94
+ */
95
+ const CREDENTIALS = {
96
+ "api-key": {
97
+ secret: "openai_api_key",
98
+ env: "OPENAI_API_KEY",
99
+ placeholder: "sk-agent-kit-deep-scan-placeholder",
100
+ },
101
+ };
102
+
103
+ /** The Launcher's config file, as TOML. Without a proxy address, no base URL. */
104
+ function configToml({ proxyUrl, workspace }) {
105
+ // A TOML basic string takes JSON's escapes.
106
+ const quoted = (s) => JSON.stringify(s);
107
+ return [
108
+ "# Written by the agent-kit Launcher for this run.",
109
+ `model_provider = ${quoted(PROVIDER)}`,
110
+ 'approval_policy = "never"',
111
+ 'sandbox_mode = "danger-full-access"',
112
+ 'web_search = "disabled"',
113
+ UPDATE_CHECK_OFF,
114
+ "project_doc_max_bytes = 0",
115
+ "",
116
+ "[analytics]",
117
+ "enabled = false",
118
+ "",
119
+ "[feedback]",
120
+ "enabled = false",
121
+ "",
122
+ "[history]",
123
+ 'persistence = "none"',
124
+ "",
125
+ `[projects.${quoted(workspace)}]`,
126
+ 'trust_level = "untrusted"',
127
+ "",
128
+ "[features]",
129
+ ...FEATURES_OFF.map((feature) => `${feature} = false`),
130
+ "",
131
+ `[model_providers.${PROVIDER}]`,
132
+ `name = ${quoted(PROVIDER)}`,
133
+ ...(proxyUrl !== undefined ? [`base_url = ${quoted(`${proxyUrl}/v1`)}`] : []),
134
+ 'env_key = "OPENAI_API_KEY"',
135
+ 'wire_api = "responses"',
136
+ "supports_websockets = false",
137
+ "",
138
+ `[model_providers.${PROVIDER}.capabilities]`,
139
+ 'remote_compaction = "unsupported"',
140
+ "external_web_access = false",
141
+ "",
142
+ ].join("\n");
143
+ }
144
+
145
+ /**
146
+ * The launch plan for `request`.
147
+ * @param {object} [request] a Stage request, as the Claude Code adapter
148
+ * describes it, with `workspace`, the repository's folder in the sandbox.
149
+ * `maxTurns` is ignored: Codex CLI has no turn limit. The only
150
+ * `credentialKind` is `api-key`.
151
+ * @returns the nine-part launch plan, in the same shape as Claude Code's.
152
+ */
153
+ export function codex({
154
+ model,
155
+ effort,
156
+ credentialKind = "api-key",
157
+ proxyUrl,
158
+ briefPath,
159
+ kitDir = "/agent-kit",
160
+ workspace = "/workspace",
161
+ callerKey,
162
+ } = {}) {
163
+ if (!Object.hasOwn(CREDENTIALS, credentialKind)) {
164
+ throw new Error(`Codex CLI has no credential kind ${JSON.stringify(credentialKind)}`);
165
+ }
166
+ const accepted = structuredClone(CREDENTIALS);
167
+ const credential = accepted[credentialKind];
168
+ if (callerKey !== undefined) credential.placeholder = callerKey;
169
+ const home = `${kitDir}/codex`;
170
+ return {
171
+ identity: { name: "codex", displayName: "Codex CLI", version: VERSION, major: 0 },
172
+ installLayer: {
173
+ image: `${IMAGE}@${IMAGE_DIGEST}`,
174
+ env: [],
175
+ run: [
176
+ "ln -sf /opt/agent-kit/bin/codex /usr/local/bin/codex \\",
177
+ " && mkdir -p /etc/codex \\",
178
+ ` && printf '%s\\n' '${UPDATE_CHECK_OFF}' > /etc/codex/config.toml`,
179
+ ],
180
+ },
181
+ modelRoute: { profile: "openai" },
182
+ credentials: {
183
+ accepted,
184
+ scrub: ["OPENAI_API_KEY", "CODEX_API_KEY", "CODEX_ACCESS_TOKEN"],
185
+ },
186
+ launch: {
187
+ argv: [
188
+ "codex",
189
+ "exec",
190
+ // Its events go to stdout, the transcript, and not to its error output.
191
+ "--json",
192
+ "--strict-config",
193
+ "--skip-git-repo-check",
194
+ "--ephemeral",
195
+ "--ignore-rules",
196
+ "--dangerously-bypass-approvals-and-sandbox",
197
+ ...(model !== undefined ? ["--model", model] : []),
198
+ ...(effort !== undefined ? ["--config", `model_reasoning_effort="${effort}"`] : []),
199
+ // The prompt is read from stdin.
200
+ "-",
201
+ ],
202
+ stdin: briefPath !== undefined ? { file: briefPath } : null,
203
+ files: [{ path: `${home}/config.toml`, text: configToml({ proxyUrl, workspace }) }],
204
+ env: [
205
+ `${credential.env}=${credential.placeholder}`,
206
+ `CODEX_HOME=${home}`,
207
+ // Codex takes its base URL from the config; the shell is told it too,
208
+ // as OpenAI's own clients read it: the API's base, `/v1` included.
209
+ ...(proxyUrl !== undefined ? [`OPENAI_BASE_URL=${proxyUrl}/v1`] : []),
210
+ ],
211
+ // The Launcher removes `checkoutConfig` from the copy before the launch.
212
+ removeCheckoutConfig: true,
213
+ },
214
+ checkoutConfig: [".codex", ".agents/plugins", ".agents/skills"],
215
+ instructionFiles: ["AGENTS.md", "AGENTS.override.md"],
216
+ stops: { turnCap: null },
217
+ transcript: { path: `${kitDir}/logs/agent.log` },
218
+ };
219
+ }
@@ -0,0 +1,199 @@
1
+ // The Cursor CLI Harness adapter (ADR 0027): one function that takes a Stage
2
+ // request and returns a launch plan, as plain data. The Launcher does
3
+ // everything with the plan; this module starts nothing and imports nothing.
4
+ //
5
+ // Cursor CLI is the one harness the model proxy cannot front: every model
6
+ // request goes through Cursor's own backend. Its key and network Guards take
7
+ // the fixed weaker form of ADR 0025, on plan, implement and review only:
8
+ //
9
+ // - egress: the sandbox reaches Cursor's hosts (HOSTS, below) and nothing
10
+ // else, through the Launcher's allowlist proxy (`modelRoute.egress`);
11
+ // - key: `CURSOR_API_KEY` itself sits in the sandbox, the one secret passed
12
+ // in; there is no placeholder;
13
+ // - result: the Launcher refuses a Stage result, or an agent's commit
14
+ // (binary files included), that holds the key (`refuseHeldKey`, in
15
+ // cli/src/stage/egress-route.mjs). The commits are scanned on the host,
16
+ // from the bundle that came out, never by the sandbox's git. The transcript and error output stay
17
+ // private on the runner and are not checked. The key reaches the sandbox
18
+ // through the runtime CLI's environment, never its command line.
19
+ //
20
+ // It is refused for Review response, the static security audit and the Deep
21
+ // scan (harness/resolve.mjs and the reusable workflows), and capped at `tried`
22
+ // (ADR 0028): Cursor's backend changes behind the pinned binary.
23
+ //
24
+ // The CLI: one pinned version, in `/opt/agent-kit` of the kit's Harness image
25
+ // (ADR 0029), pinned by digest. Cursor became Grok Build on 2026-11-30; this
26
+ // is the legacy Cursor CLI (`cursor-agent`, dated versions like
27
+ // `2026.12.02-8b70b6c`), not xAI's `grok` 2.x CLI (versions `2.…`), which
28
+ // takes other flags, another key and other hosts
29
+ // (docs/research/cursor-grok-build.md). `cursor-agent update --channel grok`
30
+ // would replace it with `grok`, recorded in `grok-switch.json` in
31
+ // `CURSOR_CONFIG_DIR`. None of that can happen here: the image is
32
+ // root-owned, no update host (`downloads.cursor.com`, `x.ai`,
33
+ // `storage.googleapis.com`) is allowed, `CURSOR_CONFIG_DIR` is the run's own
34
+ // fresh directory with no switch record, and the image build and the live
35
+ // workflow fail unless `--version` prints this dated pin (VERSION_FORM). The launch: headless
36
+ // (`-p`), every tool approved (`--force`) since the Launcher's sandbox reaches
37
+ // the Guards, the prompt as the one argument (the brief is a file it names).
38
+ // The checkout's Cursor config (`.cursor/`, `.cursorrules`, `.agents/skills`,
39
+ // `.env`) is removed from the copy; the run's own `cli-config.json`, under a
40
+ // `CURSOR_CONFIG_DIR` of the Launcher's, denies Cursor's web tools where its
41
+ // permission rules allow it.
42
+
43
+ /** The Cursor CLI version every sandbox runs, pinned (a `lab/<version>` package). */
44
+ const VERSION = "2026.12.02-8b70b6c";
45
+
46
+ /**
47
+ * The legacy Cursor CLI's version form. The image build checks its pin with
48
+ * the same pattern (a test holds docker/harness-images/cursor.Dockerfile to it).
49
+ */
50
+ export const VERSION_FORM = /^[0-9]{4}\.[0-9]{2}\.[0-9]{2}-[0-9a-f]{7,}$/;
51
+
52
+ /** What `grok` 2.x prints for `--version` (versions `2.…`), in the image build too. */
53
+ export const GROK_VERSION = /^(grok[^ ]* +)?v?2\.[0-9]/i;
54
+
55
+ /**
56
+ * The Harness image that holds that version. The `harness-images` workflow
57
+ * builds it in the pull request that changes the pin or its Dockerfile, and
58
+ * fails until this holds the digest it pushed
59
+ * (`node docker/harness-images/image.mjs record cursor`).
60
+ */
61
+ const IMAGE = "ghcr.io/mnaimfaizy/agent-kit-sandbox-cursor";
62
+ const IMAGE_DIGEST = "sha256:557d45d4952ad836b3df9005a2f7768ca16861f2d9a104c54da17bcbab206aa8"; // inputs-e5fe4cda6fcdda6920a56a7acdb51e73
63
+
64
+ /**
65
+ * What a Consumer needs to know about Cursor CLI, which `cli/harnesses.json`
66
+ * publishes per tag (ADR 0030): the kit secret it accepts, with where to get
67
+ * it; no effort values (the pinned version has no effort setting); and the
68
+ * model a Stage gets when none is named, Cursor's own `auto`.
69
+ */
70
+ export const FACTS = Object.freeze({
71
+ displayName: "Cursor CLI",
72
+ secrets: Object.freeze([
73
+ {
74
+ name: "cursor_api_key",
75
+ whereToGet:
76
+ 'Create an API key with the permission "Sign in to the Cursor CLI and SDK" in the Grok Build dashboard (Cursor is now Grok Build): https://grok.com/dashboard/api-keys. An existing Cursor (legacy) key keeps working. It sits in the sandbox for the run, so use one from an account with its own spend limit.',
77
+ },
78
+ ]),
79
+ effortValues: Object.freeze([]),
80
+ defaultModel: "auto",
81
+ });
82
+
83
+ /**
84
+ * The hosts the sandbox may reach, each on port 443: the ones Cursor's
85
+ * network configuration page lists for agent requests (`api2` for most API
86
+ * requests, `api5` for agent requests, `api3`, `api4` and `repo42` for tab
87
+ * and codebase search). Exact names, no wildcard: the allowlist proxy takes
88
+ * none, and `downloads.cursor.com` (updates) is left out on purpose.
89
+ * Of the page's `agent*.api5.cursor.sh` subdomains, which it gives only for
90
+ * "network access layer (NAL) requests" and ties to no client, one is on the
91
+ * list: a live probe on 2026-12-04 (Cursor CLI 2026.12.02-8b70b6c) was refused
92
+ * on `agentn.global.api5.cursor.sh` with an HTTPS proxy CONNECT 403. The other
93
+ * `agent*.api5.cursor.sh` names stay out until a run shows the CLI needs one.
94
+ * Left out too: its sign-in hosts (an API key opens no sign-in page); and
95
+ * every `x.ai`, `grok.com` or `spacexsi.com` host, which serve `grok` 2.x or
96
+ * browser sign-in, not this CLI.
97
+ * Source: https://docs.grok.com/build/agents-window/enterprise/network-configuration
98
+ */
99
+ export const HOSTS = Object.freeze([
100
+ "api2.cursor.sh",
101
+ "api3.cursor.sh",
102
+ "api4.cursor.sh",
103
+ "api5.cursor.sh",
104
+ "repo42.cursor.sh",
105
+ "agentn.global.api5.cursor.sh",
106
+ ]);
107
+
108
+ /** The credential Cursor CLI accepts: the key itself, held in the sandbox. */
109
+ const CREDENTIALS = {
110
+ "api-key": { secret: "cursor_api_key", env: "CURSOR_API_KEY", placeholder: "" },
111
+ };
112
+
113
+ /** The run's own CLI config: no web tools, and the permissions a headless run needs. */
114
+ const CONFIG = {
115
+ version: 1,
116
+ permissions: {
117
+ allow: ["Read(**)", "Write(**)", "Shell(*)"],
118
+ deny: ["WebFetch(*)", "WebSearch(*)"],
119
+ },
120
+ };
121
+
122
+ /**
123
+ * The launch plan for `request`.
124
+ * @param {object} [request] a Stage request, as the Claude Code adapter
125
+ * describes it, with these differences. `proxyUrl` is the Launcher's
126
+ * allowlist proxy, not a model proxy. `callerKey` is the Cursor API key
127
+ * itself, which the sandbox holds; without it the plan holds none. `effort`
128
+ * and `maxTurns` are ignored: Cursor CLI has neither.
129
+ * @returns the nine-part launch plan, in the same shape as Claude Code's.
130
+ */
131
+ export function cursor({
132
+ model,
133
+ credentialKind = "api-key",
134
+ proxyUrl,
135
+ briefPath,
136
+ kitDir,
137
+ callerKey,
138
+ } = {}) {
139
+ if (!Object.hasOwn(CREDENTIALS, credentialKind)) {
140
+ throw new Error(`Cursor CLI has no credential kind ${JSON.stringify(credentialKind)}`);
141
+ }
142
+ const accepted = structuredClone(CREDENTIALS);
143
+ const credential = accepted[credentialKind];
144
+ if (callerKey !== undefined) credential.placeholder = callerKey;
145
+ const home = kitDir ?? "/agent-kit";
146
+ const config = `${home}/cursor`;
147
+ return {
148
+ identity: { name: "cursor", displayName: "Cursor CLI", version: VERSION, major: 2026 },
149
+ installLayer: {
150
+ image: `${IMAGE}@${IMAGE_DIGEST}`,
151
+ env: [],
152
+ run: ["ln -sf /opt/agent-kit/bin/cursor-agent /usr/local/bin/cursor-agent"],
153
+ },
154
+ // No model proxy: the egress allowlist, to the hosts above, is the route.
155
+ modelRoute: { profile: null, egress: { hosts: [...HOSTS] } },
156
+ credentials: { accepted, scrub: ["CURSOR_API_KEY"] },
157
+ launch: {
158
+ argv: [
159
+ "sh",
160
+ "-c",
161
+ // The prompt is the one argument, read from the file the Launcher wrote.
162
+ `exec cursor-agent -p --force --trust --output-format text${model !== undefined ? ` --model '${model.replace(/'/g, "")}'` : ""} "$(cat ${briefPath ?? `${home}/in/prompt.md`})"`,
163
+ ],
164
+ stdin: null,
165
+ files: [{ path: `${config}/cli-config.json`, text: JSON.stringify(CONFIG, null, 2) }],
166
+ env: [
167
+ ...(credential.placeholder !== "" ? [`${credential.env}=${credential.placeholder}`] : []),
168
+ `CURSOR_CONFIG_DIR=${config}`,
169
+ "NO_COLOR=1",
170
+ ...(proxyUrl !== undefined
171
+ ? [
172
+ `HTTPS_PROXY=${proxyUrl}`,
173
+ `HTTP_PROXY=${proxyUrl}`,
174
+ `ALL_PROXY=${proxyUrl}`,
175
+ "NODE_USE_ENV_PROXY=1",
176
+ ]
177
+ : []),
178
+ ],
179
+ // The Launcher removes `checkoutConfig` from the copy before the launch.
180
+ // The runtime CLI is given the name alone; the value goes in its environment.
181
+ secretEnv: ["CURSOR_API_KEY"],
182
+ removeCheckoutConfig: true,
183
+ },
184
+ checkoutConfig: [".cursor", ".cursorrules", ".agents/skills", ".env"],
185
+ instructionFiles: ["AGENTS.md", "CLAUDE.md"],
186
+ stops: { turnCap: null },
187
+ transcript: { path: `${home}/logs/agent.log` },
188
+ };
189
+ }
190
+
191
+ /** What a Stage says that differs by harness (cli/src/deep-scan/harness-text.mjs). */
192
+ export const TEXT = Object.freeze({
193
+ webOff: "Cursor CLI's web fetch and web search are denied in its run config",
194
+ agentStep: () =>
195
+ "the API key in the sandbox, egress to Cursor's hosts alone, web tools denied, the checkout's Cursor config removed",
196
+ turnLimit: false,
197
+ needsKey: "Cursor CLI needs a Cursor API key",
198
+ keyRefused: "Check that the key is current and its Cursor account is active",
199
+ });
@@ -0,0 +1,21 @@
1
+ // The Custom harnesses this process has loaded from a trusted commit, by their
2
+ // `custom:<name>`. Whatever looks a harness up by name finds a loaded one here
3
+ // beside the kit's own. It imports nothing, so anything may import it.
4
+
5
+ /** @type {Map<string, { adapter: Function, facts: object, text: object }>} */
6
+ const loaded = new Map();
7
+
8
+ /** Whether `harness` names a Custom harness. */
9
+ export const isCustom = (harness) => typeof harness === "string" && harness.startsWith("custom:");
10
+
11
+ /**
12
+ * @param {string} harness `custom:<name>`
13
+ * @param {{ adapter: Function, facts: object, text: object }} entry
14
+ */
15
+ export function registerCustom(harness, entry) {
16
+ if (!isCustom(harness)) throw new Error(`not a Custom harness: ${JSON.stringify(harness)}`);
17
+ loaded.set(harness, entry);
18
+ }
19
+
20
+ /** The loaded Custom harness `harness`, or undefined. */
21
+ export const loadedCustom = (harness) => loaded.get(harness);