@mnaimfaizy/agent-kit 1.0.0-beta.14 → 1.0.0-beta.16
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.
- package/README.md +22 -4
- package/custom-harness.schema.json +243 -0
- package/harnesses.json +244 -6
- package/package.json +3 -2
- package/src/checks/ci-workflow.mjs +105 -0
- package/src/checks/claude-app.mjs +11 -2
- package/src/checks/custom-harness.mjs +157 -0
- package/src/checks/github-app.mjs +214 -0
- package/src/checks/rulesets.mjs +9 -8
- package/src/checks/secrets-and-variables.mjs +27 -8
- package/src/checks/stages.mjs +705 -0
- package/src/cli.mjs +583 -36
- package/src/deep-scan/agent.mjs +88 -21
- package/src/deep-scan/credential.mjs +81 -32
- package/src/deep-scan/docker-driver.mjs +105 -42
- package/src/deep-scan/harness-text.mjs +99 -0
- package/src/deep-scan/lifecycle.mjs +68 -178
- package/src/deep-scan/limits.mjs +13 -7
- package/src/deep-scan/model-proxy.mjs +21 -10
- package/src/deep-scan/preflight.mjs +19 -6
- package/src/deep-scan/recipe.mjs +4 -0
- package/src/deep-scan/runtime.mjs +54 -6
- package/src/deep-scan/sandbox-run.mjs +232 -0
- package/src/deep-scan/sbx-driver.mjs +224 -39
- package/src/deep-scan/tar.mjs +69 -22
- package/src/deep-scan/verify.mjs +6 -1
- package/src/deep-scan.mjs +73 -13
- package/src/doctor.mjs +166 -5
- package/src/exec.mjs +14 -5
- package/src/factory/budget/budget.mjs +259 -0
- package/src/factory/build/command.mjs +321 -0
- package/src/factory/build/factory.mjs +473 -0
- package/src/factory/build/findings.mjs +55 -0
- package/src/factory/build/host.mjs +230 -0
- package/src/factory/build/notes.mjs +191 -0
- package/src/factory/build/pull-request.mjs +74 -0
- package/src/factory/bundle.mjs +146 -0
- package/src/factory/checks/allowed-paths.mjs +50 -0
- package/src/factory/checks/plan-header.mjs +296 -0
- package/src/factory/checks/qa.mjs +85 -0
- package/src/factory/checks/review.mjs +73 -0
- package/src/factory/checks/security.mjs +50 -0
- package/src/factory/checks/stage-check.mjs +89 -0
- package/src/factory/claims/command.mjs +187 -0
- package/src/factory/claims/release.mjs +111 -0
- package/src/factory/decision/answers.mjs +103 -0
- package/src/factory/decision/command.mjs +64 -0
- package/src/factory/decision/plan.mjs +99 -0
- package/src/factory/decision/request.mjs +116 -0
- package/src/factory/doctor/files.mjs +329 -0
- package/src/factory/doctor/index.mjs +56 -0
- package/src/factory/doctor/local.mjs +497 -0
- package/src/factory/doctor/orchestrate.mjs +146 -0
- package/src/factory/engine/lease.mjs +146 -0
- package/src/factory/engine/local-engine.mjs +177 -0
- package/src/factory/engine/lockfile.mjs +64 -0
- package/src/factory/engine/workflow-engine.mjs +124 -0
- package/src/factory/gate/comment.mjs +88 -0
- package/src/factory/gate/config.mjs +57 -0
- package/src/factory/gate/gate-core.mjs +250 -0
- package/src/factory/gate/guarded.mjs +17 -0
- package/src/factory/gate/reads.mjs +105 -0
- package/src/factory/gate/task.mjs +193 -0
- package/src/factory/gate/trip-reads.mjs +82 -0
- package/src/factory/gate/trip.mjs +87 -0
- package/src/factory/init/blueprint.mjs +174 -0
- package/src/factory/init/index.mjs +337 -0
- package/src/factory/labels/evidence.mjs +162 -0
- package/src/factory/labels/moves.mjs +32 -0
- package/src/factory/labels/reconcile.mjs +267 -0
- package/src/factory/labels/revert.mjs +87 -0
- package/src/factory/labels/timeline.mjs +72 -0
- package/src/factory/labels/voided.mjs +59 -0
- package/src/factory/limits/harness.mjs +39 -0
- package/src/factory/limits/limits.mjs +123 -0
- package/src/factory/merge/command.mjs +172 -0
- package/src/factory/outbox/check.mjs +240 -0
- package/src/factory/outbox/rulings.mjs +195 -0
- package/src/factory/plan/command.mjs +66 -0
- package/src/factory/plan/comment.mjs +156 -0
- package/src/factory/plan/publish.mjs +149 -0
- package/src/factory/plan/risk.mjs +153 -0
- package/src/factory/qa/command.mjs +163 -0
- package/src/factory/records/engine-record.mjs +133 -0
- package/src/factory/records/main.mjs +96 -0
- package/src/factory/records/record.mjs +226 -0
- package/src/factory/records/sink.mjs +57 -0
- package/src/factory/report/build.mjs +92 -0
- package/src/factory/report/command.mjs +80 -0
- package/src/factory/report/facts.mjs +226 -0
- package/src/factory/report/gate-section.mjs +122 -0
- package/src/factory/report/metrics.mjs +111 -0
- package/src/factory/report/reads.mjs +246 -0
- package/src/factory/report/render.mjs +121 -0
- package/src/factory/report/rollout.mjs +154 -0
- package/src/factory/review/command.mjs +182 -0
- package/src/factory/run/awake.mjs +70 -0
- package/src/factory/run/collect.mjs +77 -0
- package/src/factory/run/command.mjs +490 -0
- package/src/factory/run/gh.mjs +46 -0
- package/src/factory/run/launch.mjs +47 -0
- package/src/factory/run/pipelines.mjs +261 -0
- package/src/factory/run/raw.mjs +96 -0
- package/src/factory/run/restart.mjs +83 -0
- package/src/factory/run/s3.mjs +193 -0
- package/src/factory/run/secrets.mjs +142 -0
- package/src/factory/run/teardown.mjs +242 -0
- package/src/factory/run/token.mjs +68 -0
- package/src/factory/security/command.mjs +157 -0
- package/src/factory/setup/app.mjs +122 -0
- package/src/factory/setup/command.mjs +409 -0
- package/src/factory/setup/labels.mjs +25 -0
- package/src/factory/setup/reads.mjs +129 -0
- package/src/factory/setup/writes.mjs +126 -0
- package/src/factory/snapshot/write.mjs +176 -0
- package/src/factory/stop/command.mjs +136 -0
- package/src/factory/sweep/actions-main.mjs +117 -0
- package/src/factory/sweep/command.mjs +65 -0
- package/src/factory/sweep/knobs.mjs +78 -0
- package/src/factory/sweep/marker-version.mjs +15 -0
- package/src/factory/sweep/markers.mjs +112 -0
- package/src/factory/sweep/overlap.mjs +24 -0
- package/src/factory/sweep/run.mjs +198 -0
- package/src/factory/sweep/shell.mjs +394 -0
- package/src/factory/sweep/split.mjs +104 -0
- package/src/factory/sweep/states.mjs +87 -0
- package/src/factory/sweep/sweep-core.mjs +1781 -0
- package/src/factory/tracker/github.mjs +674 -0
- package/src/factory/tracker/operations.mjs +153 -0
- package/src/factory/upgrade/index.mjs +83 -0
- package/src/harness/adapters.mjs +30 -0
- package/src/harness/antigravity.mjs +187 -0
- package/src/harness/claude-code.mjs +8 -1
- package/src/harness/codex.mjs +219 -0
- package/src/harness/cursor.mjs +199 -0
- package/src/harness/custom/registry.mjs +21 -0
- package/src/harness/custom/schema.mjs +90 -0
- package/src/harness/custom.mjs +299 -0
- package/src/harness/facts.mjs +44 -7
- package/src/harness/gemini.mjs +164 -0
- package/src/harness/install-layer.mjs +86 -3
- package/src/harness/opencode.mjs +289 -0
- package/src/harness/resolve.mjs +156 -0
- package/src/harness/support-levels.mjs +151 -3
- package/src/harness-live/assess.mjs +29 -6
- package/src/harness-live/cursor-real.mjs +146 -0
- package/src/harness-live/cursor-version.mjs +70 -0
- package/src/harness-live/cursor.mjs +80 -0
- package/src/harness-live/custom.mjs +91 -0
- package/src/harness-live/fixture-harness.mjs +45 -0
- package/src/harness-live/harnesses.mjs +263 -0
- package/src/harness-live/host.mjs +113 -4
- package/src/harness-live/opencode.mjs +289 -0
- package/src/harness-live/probes.mjs +87 -7
- package/src/harness-live/run.mjs +101 -20
- package/src/harness-live/setup.mjs +126 -0
- package/src/harness-live/stage.mjs +25 -15
- package/src/harness-live/suite.mjs +276 -95
- package/src/harness-test.mjs +116 -0
- package/src/init.mjs +374 -36
- package/src/kit-owned-paths.mjs +1 -1
- package/src/model-proxy/core.mjs +128 -20
- package/src/model-proxy/profiles/anthropic.mjs +54 -10
- package/src/model-proxy/profiles/gemini-api.mjs +311 -0
- package/src/model-proxy/profiles/openai.mjs +327 -0
- package/src/model-proxy/stub-dialects/gemini-api.mjs +178 -0
- package/src/model-proxy/stub-dialects/openai.mjs +173 -0
- package/src/model-proxy/stub.mjs +9 -1
- package/src/stage/audit.mjs +79 -0
- package/src/stage/egress-route.mjs +207 -0
- package/src/stage/implement/carry.mjs +308 -0
- package/src/stage/implement/sandbox.mjs +271 -0
- package/src/stage/implement/verify.mjs +70 -0
- package/src/stage/implement.mjs +218 -0
- package/src/stage/plan.mjs +115 -0
- package/src/stage/review-response.mjs +172 -0
- package/src/stage/review.mjs +185 -0
- package/src/stage/workspace.mjs +274 -0
- package/src/stage.mjs +1087 -0
- package/src/upgrade.mjs +39 -7
|
@@ -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);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// The JSON Schema keywords the Custom harness schema uses, and no others: the
|
|
2
|
+
// CLI has no dependencies. `doctor` validates against the pinned tag's schema,
|
|
3
|
+
// so a keyword this version does not know throws and never passes unseen.
|
|
4
|
+
// `errorMessage` replaces what a failing subschema says.
|
|
5
|
+
|
|
6
|
+
const KNOWN = new Set([
|
|
7
|
+
"$schema",
|
|
8
|
+
"title",
|
|
9
|
+
"description",
|
|
10
|
+
"errorMessage",
|
|
11
|
+
"type",
|
|
12
|
+
"enum",
|
|
13
|
+
"pattern",
|
|
14
|
+
"maxLength",
|
|
15
|
+
"minItems",
|
|
16
|
+
"items",
|
|
17
|
+
"properties",
|
|
18
|
+
"required",
|
|
19
|
+
"additionalProperties",
|
|
20
|
+
"propertyNames",
|
|
21
|
+
"anyOf",
|
|
22
|
+
"not",
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const typeOf = (value) => (value === null ? "null" : Array.isArray(value) ? "array" : typeof value);
|
|
26
|
+
|
|
27
|
+
const at = (path, key) => (path === "" ? key : `${path}.${key}`);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Why `value` does not match `schema`, one line per problem, each naming where.
|
|
31
|
+
* @param {object} schema
|
|
32
|
+
* @param {unknown} value
|
|
33
|
+
* @param {string} [path]
|
|
34
|
+
* @returns {string[]}
|
|
35
|
+
*/
|
|
36
|
+
export function problems(schema, value, path = "") {
|
|
37
|
+
const unknown = Object.keys(schema).find((keyword) => !KNOWN.has(keyword));
|
|
38
|
+
if (unknown !== undefined) {
|
|
39
|
+
throw new Error(`the Custom harness schema uses ${unknown}, which this version cannot check`);
|
|
40
|
+
}
|
|
41
|
+
const where = path === "" ? "the file" : path;
|
|
42
|
+
const own = (said) => [`${where}: ${schema.errorMessage ?? said}`];
|
|
43
|
+
if (schema.not !== undefined && problems(schema.not, value, path).length === 0) {
|
|
44
|
+
return own("is not allowed");
|
|
45
|
+
}
|
|
46
|
+
if (schema.type !== undefined && typeOf(value) !== schema.type) {
|
|
47
|
+
return own(`must be of type ${schema.type}`);
|
|
48
|
+
}
|
|
49
|
+
if (schema.enum !== undefined && !schema.enum.includes(value)) {
|
|
50
|
+
return own(`must be one of ${schema.enum.join(", ")}`);
|
|
51
|
+
}
|
|
52
|
+
if (schema.anyOf !== undefined && !schema.anyOf.some((s) => !problems(s, value, path).length)) {
|
|
53
|
+
return own("matches none of the forms it may take");
|
|
54
|
+
}
|
|
55
|
+
const found = [];
|
|
56
|
+
if (typeof value === "string") {
|
|
57
|
+
if (schema.maxLength !== undefined && value.length > schema.maxLength) {
|
|
58
|
+
return own(`is longer than ${schema.maxLength} characters`);
|
|
59
|
+
}
|
|
60
|
+
if (schema.pattern !== undefined && !new RegExp(schema.pattern, "u").test(value)) {
|
|
61
|
+
return own(`must match ${schema.pattern}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (Array.isArray(value)) {
|
|
65
|
+
if (schema.minItems !== undefined && value.length < schema.minItems) {
|
|
66
|
+
return own(`needs at least ${schema.minItems} item(s)`);
|
|
67
|
+
}
|
|
68
|
+
if (schema.items !== undefined) {
|
|
69
|
+
value.forEach((item, i) => found.push(...problems(schema.items, item, `${path}[${i}]`)));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (typeOf(value) === "object") {
|
|
73
|
+
for (const name of schema.required ?? []) {
|
|
74
|
+
if (!Object.hasOwn(value, name)) found.push(`${where}: the ${name} key is missing`);
|
|
75
|
+
}
|
|
76
|
+
for (const [key, item] of Object.entries(value)) {
|
|
77
|
+
if (schema.propertyNames !== undefined) {
|
|
78
|
+
found.push(...problems(schema.propertyNames, key, at(path, key)));
|
|
79
|
+
}
|
|
80
|
+
if (Object.hasOwn(schema.properties ?? {}, key)) {
|
|
81
|
+
found.push(...problems(schema.properties[key], item, at(path, key)));
|
|
82
|
+
} else if (schema.additionalProperties === false) {
|
|
83
|
+
found.push(`${where}: unknown key ${JSON.stringify(key)}`);
|
|
84
|
+
} else if (schema.additionalProperties !== undefined) {
|
|
85
|
+
found.push(...problems(schema.additionalProperties, item, at(path, key)));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return found;
|
|
90
|
+
}
|