@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.
- package/README.md +24 -5
- package/custom-harness.schema.json +243 -0
- package/harnesses.json +286 -0
- package/package.json +4 -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/review-response.mjs +54 -27
- package/src/checks/rulesets.mjs +9 -8
- package/src/checks/secrets-and-variables.mjs +220 -43
- package/src/checks/stages.mjs +705 -0
- package/src/cli.mjs +277 -31
- package/src/deep-scan/agent.mjs +145 -117
- package/src/deep-scan/credential.mjs +88 -42
- package/src/deep-scan/docker-driver.mjs +131 -49
- package/src/deep-scan/harness-text.mjs +99 -0
- package/src/deep-scan/lifecycle.mjs +92 -199
- package/src/deep-scan/limits.mjs +13 -7
- package/src/deep-scan/model-proxy.mjs +47 -602
- package/src/deep-scan/preflight.mjs +81 -1
- package/src/deep-scan/recipe.mjs +7 -7
- package/src/deep-scan/runtime.mjs +54 -6
- package/src/deep-scan/sandbox-run.mjs +232 -0
- package/src/deep-scan/sbx-driver.mjs +242 -50
- package/src/deep-scan/tar.mjs +69 -22
- package/src/deep-scan/verify.mjs +6 -1
- package/src/deep-scan.mjs +98 -14
- package/src/doctor.mjs +113 -4
- package/src/harness/adapters.mjs +30 -0
- package/src/harness/antigravity.mjs +187 -0
- package/src/harness/claude-code.mjs +236 -0
- 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 +157 -0
- package/src/harness/gemini.mjs +164 -0
- package/src/harness/install-layer.mjs +141 -0
- package/src/harness/opencode.mjs +289 -0
- package/src/harness/resolve.mjs +156 -0
- package/src/harness/support-levels.mjs +197 -0
- package/src/harness-live/assess.mjs +291 -0
- 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 +414 -0
- package/src/harness-live/opencode.mjs +289 -0
- package/src/harness-live/probes.mjs +239 -0
- package/src/harness-live/run.mjs +214 -0
- package/src/harness-live/setup.mjs +126 -0
- package/src/harness-live/stage.mjs +161 -0
- package/src/harness-live/suite.mjs +481 -0
- package/src/harness-test.mjs +116 -0
- package/src/init.mjs +339 -23
- package/src/model-proxy/core.mjs +657 -0
- package/src/model-proxy/profiles/anthropic.mjs +241 -0
- 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/anthropic.mjs +110 -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 +182 -0
- 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 +1068 -0
- package/src/deep-scan/claude-code.mjs +0 -25
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// The Gemini 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, beside the
|
|
7
|
+
// Node it runs on. The updater is off in the system settings the image holds
|
|
8
|
+
// and in the run's own. Nothing is installed at run time.
|
|
9
|
+
//
|
|
10
|
+
// The launch: headless, the brief on stdin, every tool approved (`yolo`),
|
|
11
|
+
// since the Launcher's sandbox reaches the Guards. Gemini CLI approves tools
|
|
12
|
+
// only in a trusted folder, and a trusted folder loads the checkout's
|
|
13
|
+
// `.gemini/` (settings, `.env`, MCP servers, hooks, commands, skills), so the
|
|
14
|
+
// Launcher removes it from the copy, with `.agents/skills` and `.env`. The
|
|
15
|
+
// pins (the web tools excluded, hooks, subagents, usage statistics and the
|
|
16
|
+
// update check off, API-key sign-in) are written twice: as the image's system
|
|
17
|
+
// settings, which Gemini CLI reads only when root owns the file and which
|
|
18
|
+
// outrank a project's, so a checkout cannot disable a hook or turn a web tool
|
|
19
|
+
// back on; and as the run's user settings, under a `GEMINI_CLI_HOME` of the
|
|
20
|
+
// Launcher's own. MCP servers are limited to a name no server has, and no
|
|
21
|
+
// extension is loaded. `GEMINI.md` files are instruction files Gemini CLI
|
|
22
|
+
// loads by itself, which no setting turns off in a trusted folder.
|
|
23
|
+
//
|
|
24
|
+
// The model API's base URL is the model proxy, over plain HTTP: Gemini CLI
|
|
25
|
+
// documents HTTPS for any host but loopback and does not enforce it at the
|
|
26
|
+
// pinned version (ADR 0023). The live suite names that cause if a bump does.
|
|
27
|
+
//
|
|
28
|
+
// The agent holds only the run's caller key as its `GEMINI_API_KEY`. Its turn
|
|
29
|
+
// limit is `model.maxSessionTurns`, and a hit one is said on its error output.
|
|
30
|
+
|
|
31
|
+
/** The Gemini CLI version every sandbox runs, pinned. */
|
|
32
|
+
const VERSION = "0.71.1";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The Harness image that holds that version. The `harness-images` workflow
|
|
36
|
+
* builds it in the pull request that changes the pin or its Dockerfile, and
|
|
37
|
+
* fails until this holds the digest it pushed
|
|
38
|
+
* (`node docker/harness-images/image.mjs record gemini`).
|
|
39
|
+
*/
|
|
40
|
+
const IMAGE = "ghcr.io/mnaimfaizy/agent-kit-sandbox-gemini";
|
|
41
|
+
const IMAGE_DIGEST = "sha256:7fb81b5c43de8b620508936a2e77de209aa590c888a5bd0fd4c4a7133e674945"; // inputs-d7c637b35a9dafe844c8fb3316b5589d
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* What a Consumer needs to know about Gemini CLI, which `cli/harnesses.json`
|
|
45
|
+
* publishes per tag (ADR 0030): the kit secret it accepts, with where to get
|
|
46
|
+
* it; no effort values, since the pinned version has no effort setting; and
|
|
47
|
+
* the model a Stage gets when none is named, which is the pinned version's own
|
|
48
|
+
* default (`auto` picks a model for each task).
|
|
49
|
+
*/
|
|
50
|
+
export const FACTS = Object.freeze({
|
|
51
|
+
displayName: "Gemini CLI",
|
|
52
|
+
secrets: Object.freeze([
|
|
53
|
+
{
|
|
54
|
+
name: "gemini_api_key",
|
|
55
|
+
whereToGet:
|
|
56
|
+
"Create an API key in Google AI Studio, in a project with its own budget: https://aistudio.google.com/apikey.",
|
|
57
|
+
},
|
|
58
|
+
]),
|
|
59
|
+
effortValues: Object.freeze([]),
|
|
60
|
+
defaultModel: "auto",
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/** The tools of Gemini CLI's own that reach outside the sandbox. */
|
|
64
|
+
export const WEB_TOOLS = Object.freeze(["google_web_search", "web_fetch"]);
|
|
65
|
+
|
|
66
|
+
/** An MCP server name nothing declares: only a server so named could start. */
|
|
67
|
+
const NO_MCP_SERVER = "agent-kit-none";
|
|
68
|
+
|
|
69
|
+
/** The credential Gemini CLI accepts, and the placeholder the model proxy swaps. */
|
|
70
|
+
const CREDENTIALS = {
|
|
71
|
+
"api-key": {
|
|
72
|
+
secret: "gemini_api_key",
|
|
73
|
+
env: "GEMINI_API_KEY",
|
|
74
|
+
placeholder: "agent-kit-deep-scan-placeholder",
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** The settings every run holds, in the image's system file and the run's own. */
|
|
79
|
+
const PINS = {
|
|
80
|
+
general: { enableAutoUpdate: false, enableAutoUpdateNotification: false },
|
|
81
|
+
privacy: { usageStatisticsEnabled: false },
|
|
82
|
+
security: { auth: { selectedType: "gemini-api-key", enforcedType: "gemini-api-key" } },
|
|
83
|
+
tools: { exclude: [...WEB_TOOLS], shell: { enableInteractiveShell: false } },
|
|
84
|
+
hooksConfig: { enabled: false },
|
|
85
|
+
experimental: { enableAgents: false },
|
|
86
|
+
advanced: { ignoreLocalEnv: true },
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The launch plan for `request`.
|
|
91
|
+
* @param {object} [request] a Stage request, as the Claude Code adapter
|
|
92
|
+
* describes it. `effort` is ignored: Gemini CLI has no effort setting. The
|
|
93
|
+
* only `credentialKind` is `api-key`.
|
|
94
|
+
* @returns the nine-part launch plan, in the same shape as Claude Code's.
|
|
95
|
+
*/
|
|
96
|
+
export function gemini({
|
|
97
|
+
model,
|
|
98
|
+
credentialKind = "api-key",
|
|
99
|
+
proxyUrl,
|
|
100
|
+
briefPath,
|
|
101
|
+
kitDir,
|
|
102
|
+
maxTurns,
|
|
103
|
+
callerKey,
|
|
104
|
+
} = {}) {
|
|
105
|
+
if (!Object.hasOwn(CREDENTIALS, credentialKind)) {
|
|
106
|
+
throw new Error(`Gemini CLI has no credential kind ${JSON.stringify(credentialKind)}`);
|
|
107
|
+
}
|
|
108
|
+
const accepted = structuredClone(CREDENTIALS);
|
|
109
|
+
const credential = accepted[credentialKind];
|
|
110
|
+
if (callerKey !== undefined) credential.placeholder = callerKey;
|
|
111
|
+
const home = kitDir ?? "/agent-kit";
|
|
112
|
+
const settings = {
|
|
113
|
+
...PINS,
|
|
114
|
+
...(maxTurns !== undefined ? { model: { maxSessionTurns: maxTurns } } : {}),
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
identity: { name: "gemini", displayName: "Gemini CLI", version: VERSION, major: 0 },
|
|
118
|
+
installLayer: {
|
|
119
|
+
image: `${IMAGE}@${IMAGE_DIGEST}`,
|
|
120
|
+
env: [],
|
|
121
|
+
run: [
|
|
122
|
+
"ln -sf /opt/agent-kit/bin/gemini /usr/local/bin/gemini \\",
|
|
123
|
+
" && mkdir -p /etc/gemini-cli \\",
|
|
124
|
+
` && printf '%s\\n' '${JSON.stringify(PINS)}' > /etc/gemini-cli/settings.json`,
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
modelRoute: { profile: "gemini-api" },
|
|
128
|
+
credentials: { accepted, scrub: ["GEMINI_API_KEY", "GOOGLE_API_KEY"] },
|
|
129
|
+
launch: {
|
|
130
|
+
argv: [
|
|
131
|
+
"gemini",
|
|
132
|
+
"--approval-mode",
|
|
133
|
+
"yolo",
|
|
134
|
+
// Its answer goes to stdout, the transcript, and a hit turn limit to
|
|
135
|
+
// its error output.
|
|
136
|
+
"--output-format",
|
|
137
|
+
"text",
|
|
138
|
+
"--extensions",
|
|
139
|
+
"none",
|
|
140
|
+
"--allowed-mcp-server-names",
|
|
141
|
+
NO_MCP_SERVER,
|
|
142
|
+
// The brief's folder and the report's are outside the workspace.
|
|
143
|
+
...(kitDir !== undefined ? ["--include-directories", kitDir] : []),
|
|
144
|
+
...(model !== undefined ? ["--model", model] : []),
|
|
145
|
+
],
|
|
146
|
+
stdin: briefPath !== undefined ? { file: briefPath } : null,
|
|
147
|
+
files: [{ path: `${home}/.gemini/settings.json`, text: JSON.stringify(settings, null, 2) }],
|
|
148
|
+
env: [
|
|
149
|
+
`${credential.env}=${credential.placeholder}`,
|
|
150
|
+
`GEMINI_CLI_HOME=${home}`,
|
|
151
|
+
"GEMINI_CLI_TRUST_WORKSPACE=true",
|
|
152
|
+
// No second process of its own, which a restart for memory would start.
|
|
153
|
+
"GEMINI_CLI_NO_RELAUNCH=true",
|
|
154
|
+
...(proxyUrl !== undefined ? [`GOOGLE_GEMINI_BASE_URL=${proxyUrl}`] : []),
|
|
155
|
+
],
|
|
156
|
+
// The Launcher removes `checkoutConfig` from the copy before the launch.
|
|
157
|
+
removeCheckoutConfig: true,
|
|
158
|
+
},
|
|
159
|
+
checkoutConfig: [".gemini", ".agents/skills", ".env"],
|
|
160
|
+
instructionFiles: ["GEMINI.md"],
|
|
161
|
+
stops: { turnCap: { stderrPattern: "Reached max session turns" } },
|
|
162
|
+
transcript: { path: `${home}/logs/agent.log` },
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// The Launcher's side of a launch plan's install layer (ADR 0027, ADR 0029):
|
|
2
|
+
// the Harness image, by digest only, and the Dockerfile that puts the
|
|
3
|
+
// harness on another image, by copying `/opt/agent-kit` from it. Both Deep
|
|
4
|
+
// scan drivers build that with Docker: the Docker driver as its runtime's
|
|
5
|
+
// image, the Docker Sandboxes driver as the template it loads into sbx
|
|
6
|
+
// (#375). Nothing is installed from a registry at run time, except a Custom
|
|
7
|
+
// harness (ADR 0029), which has no Harness image: its npm package is installed
|
|
8
|
+
// at its exact version, by the Docker driver as the image is built, and on
|
|
9
|
+
// Docker Sandboxes inside the empty sandbox, where the host's Docker neither
|
|
10
|
+
// installs nor runs it.
|
|
11
|
+
|
|
12
|
+
/** An image reference that ends in a sha256 digest, with nothing else on the line. */
|
|
13
|
+
const BY_DIGEST = /^[^\s@]+@sha256:[0-9a-f]{64}$/;
|
|
14
|
+
|
|
15
|
+
/** The two halves of the musl check's line: its command text never holds it whole. */
|
|
16
|
+
const MARKER = ["agent-kit", "musl-image"];
|
|
17
|
+
|
|
18
|
+
/** The line the musl check prints. */
|
|
19
|
+
export const MUSL_MARKER = MARKER.join("-");
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The build step that fails on a musl image: the harness's CLI and Node are
|
|
23
|
+
* glibc builds. A glibc image answers `getconf GNU_LIBC_VERSION`, even one
|
|
24
|
+
* that also has the musl loader installed.
|
|
25
|
+
*/
|
|
26
|
+
const MUSL_CHECK = `RUN if ! getconf GNU_LIBC_VERSION >/dev/null 2>&1 && ls /lib/ld-musl-* >/dev/null 2>&1; then printf '%s-%s\\n' ${MARKER.join(" ")} >&2; exit 1; fi`;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The base a Custom harness is installed on where no image is named, pinned by
|
|
30
|
+
* digest: Node and npm. The packages add the tools a Stage and its sandbox
|
|
31
|
+
* need, as the kit's Harness images hold them.
|
|
32
|
+
*/
|
|
33
|
+
export const CUSTOM_BASE =
|
|
34
|
+
"node:24-trixie-slim@sha256:4d00acb4bcc42c454c4eb801526f7ad7f772ea3bd4fd168c5cc2e384abcbb9d4";
|
|
35
|
+
const CUSTOM_BASE_PACKAGES = "bash ca-certificates curl git python3 python3-pip python3-venv";
|
|
36
|
+
|
|
37
|
+
/** Where a Custom harness's npm package goes, off the project's own path. */
|
|
38
|
+
const CUSTOM_PREFIX = "/opt/agent-kit/custom";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The base a Custom harness gets on Docker Sandboxes where no image is named,
|
|
42
|
+
* pinned by digest: the full Node image, which already holds what a template
|
|
43
|
+
* needs (curl, git, CA certificates, bash and the shadow tools), so the build
|
|
44
|
+
* on the host installs nothing.
|
|
45
|
+
*/
|
|
46
|
+
export const CUSTOM_SANDBOX_BASE =
|
|
47
|
+
"node:24-trixie@sha256:2d5b3bbabeb66d5e7085875cd770003ce5f8cb1fec00843ed6f48546a22cdc85";
|
|
48
|
+
|
|
49
|
+
/** The npm registry, the one host the install inside a sandbox needs. */
|
|
50
|
+
export const NPM_REGISTRY = "registry.npmjs.org";
|
|
51
|
+
|
|
52
|
+
/** Puts the installed package's commands first on the sandbox's path. */
|
|
53
|
+
const CUSTOM_PATH = `ENV PATH="${CUSTOM_PREFIX}/bin:\${PATH}"`;
|
|
54
|
+
|
|
55
|
+
/** The npm command that installs a Custom harness's package. */
|
|
56
|
+
const npmInstall = (npm, options = "") =>
|
|
57
|
+
`npm install --global --prefix ${CUSTOM_PREFIX} --no-audit --no-fund ${options}'${npm}'`;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The Docker Sandboxes template layer for a Custom harness on `base`: its path
|
|
61
|
+
* alone. Nothing of the file's goes into a build on the host.
|
|
62
|
+
* @param {string} base
|
|
63
|
+
*/
|
|
64
|
+
export function sandboxNpmLayer(base) {
|
|
65
|
+
return [`FROM ${base}`, CUSTOM_PATH, ""].join("\n");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The script that installs a Custom harness's package inside a sandbox, from
|
|
70
|
+
* the npm registry alone.
|
|
71
|
+
* @param {{ npm: string }} installLayer
|
|
72
|
+
*/
|
|
73
|
+
export function sandboxNpmInstall({ npm }) {
|
|
74
|
+
return [
|
|
75
|
+
"command -v npm >/dev/null 2>&1 || { echo 'agent-kit: a Custom harness is installed with npm, which this image lacks: name an image with Node and npm, or none.' >&2; exit 1; }",
|
|
76
|
+
npmInstall(npm, `--registry=https://${NPM_REGISTRY}/ `),
|
|
77
|
+
].join("\n");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The build step that names what a recipe's image lacks for the install. */
|
|
81
|
+
const NPM_CHECK =
|
|
82
|
+
"RUN command -v npm >/dev/null 2>&1 || { echo 'agent-kit: a Custom harness is installed with npm, which this image lacks: name an image with Node and npm, or none.' >&2; exit 1; }";
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The Dockerfile for a Custom harness (ADR 0029: it has no Harness image): its
|
|
86
|
+
* npm package at the exact version, on `base`, or on the kit's own base.
|
|
87
|
+
*/
|
|
88
|
+
function npmDockerfile(base, { npm }) {
|
|
89
|
+
return [
|
|
90
|
+
`FROM ${base ?? CUSTOM_BASE}`,
|
|
91
|
+
...(base === undefined
|
|
92
|
+
? [
|
|
93
|
+
`RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --yes --no-install-recommends ${CUSTOM_BASE_PACKAGES} && rm -rf /var/lib/apt/lists/*`,
|
|
94
|
+
"ENV PIP_BREAK_SYSTEM_PACKAGES=1",
|
|
95
|
+
]
|
|
96
|
+
: [NPM_CHECK]),
|
|
97
|
+
`RUN ${npmInstall(npm)}`,
|
|
98
|
+
CUSTOM_PATH,
|
|
99
|
+
"WORKDIR /workspace",
|
|
100
|
+
"",
|
|
101
|
+
].join("\n");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The plan's Harness image. Throws unless it is named by digest: a tag alone
|
|
106
|
+
* can come to mean another image.
|
|
107
|
+
* @param {import("./claude-code.mjs").LaunchPlan["installLayer"]} installLayer
|
|
108
|
+
* @returns {string}
|
|
109
|
+
*/
|
|
110
|
+
export function pinnedHarnessImage({ image }) {
|
|
111
|
+
if (typeof image !== "string" || !BY_DIGEST.test(image)) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`the Harness image must be pinned by digest (name@sha256:<64 hex digits>), got: ${JSON.stringify(image)}`,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
return image;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The Dockerfile that layers a plan's `installLayer` on `base`, which must be
|
|
121
|
+
* glibc Linux: the musl check, then `/opt/agent-kit` from the Harness image,
|
|
122
|
+
* its `bin` (the harness's CLI alone, never its Node) first on the path, so a
|
|
123
|
+
* CLI of the same name in the image never runs in the pinned one's place.
|
|
124
|
+
* A Custom harness's layer installs its npm package instead, and needs no
|
|
125
|
+
* `base`.
|
|
126
|
+
* @param {string | undefined} base
|
|
127
|
+
* @param {import("./claude-code.mjs").LaunchPlan["installLayer"] | { npm: string }} installLayer
|
|
128
|
+
*/
|
|
129
|
+
export function layerDockerfile(base, installLayer) {
|
|
130
|
+
if ("npm" in installLayer) return npmDockerfile(base, installLayer);
|
|
131
|
+
const { env, run } = installLayer;
|
|
132
|
+
return [
|
|
133
|
+
`FROM ${base}`,
|
|
134
|
+
MUSL_CHECK,
|
|
135
|
+
`COPY --from=${pinnedHarnessImage(installLayer)} /opt/agent-kit /opt/agent-kit`,
|
|
136
|
+
'ENV PATH="/opt/agent-kit/bin:${PATH}"',
|
|
137
|
+
...env.map((v) => `ENV ${v}`),
|
|
138
|
+
`RUN ${run.join("\n")}`,
|
|
139
|
+
"",
|
|
140
|
+
].join("\n");
|
|
141
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// The opencode 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: opencode 2.x (`@opencode/cli`), one pinned version, in
|
|
6
|
+
// `/opt/agent-kit` of the kit's Harness image (ADR 0029,
|
|
7
|
+
// docker/harness-images/), which is pinned by digest. The updater is off in
|
|
8
|
+
// the system config the image holds, in the run's own and by
|
|
9
|
+
// `OPENCODE_DISABLE_AUTOUPDATE`. Nothing is installed at run time. opencode
|
|
10
|
+
// 1.x (`opencode-ai`) is another harness, which the kit does not run.
|
|
11
|
+
//
|
|
12
|
+
// The provider is the Stage's model's: opencode names a model
|
|
13
|
+
// `provider/model`, and each provider here has a model proxy profile
|
|
14
|
+
// (ADR 0023). The accepted credential is that provider's API key.
|
|
15
|
+
//
|
|
16
|
+
// The launch: `opencode run`, the brief on stdin, always `--standalone`
|
|
17
|
+
// (without it, 2.x attaches to a shared per-user server that read its
|
|
18
|
+
// environment when it started), with every permission approved (`--auto`),
|
|
19
|
+
// since the Launcher's sandbox reaches the Guards. opencode reads the
|
|
20
|
+
// Launcher's config (`OPENCODE_CONFIG`) and a global config folder of the
|
|
21
|
+
// Launcher's own; project config is off, and the Launcher removes it from the
|
|
22
|
+
// copy too. The config names the model, one provider whose base URL is the
|
|
23
|
+
// model proxy over HTTP (`transport: "http"`, since opencode would otherwise
|
|
24
|
+
// open a WebSocket to OpenAI), and denies every other provider. Web search,
|
|
25
|
+
// web fetch and the image and video tools, sharing, the update check, the
|
|
26
|
+
// model catalogue's fetch, automations, snapshots, formatters, language
|
|
27
|
+
// servers and the title agent (a model call of its own) are off. The pins are
|
|
28
|
+
// written twice: as the image's system config, which opencode loads last, so
|
|
29
|
+
// nothing outranks it, and in the run's config.
|
|
30
|
+
//
|
|
31
|
+
// The agent holds only the run's caller key as its provider's key. opencode's
|
|
32
|
+
// step limit ends a run as if it had finished, so it is left unset: the wall
|
|
33
|
+
// clock and the proxy's token cap bound the run.
|
|
34
|
+
|
|
35
|
+
/** The opencode version every sandbox runs, pinned. */
|
|
36
|
+
const VERSION = "2.4.3";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The Harness image that holds that version. The `harness-images` workflow
|
|
40
|
+
* builds it in the pull request that changes the pin or its Dockerfile, and
|
|
41
|
+
* fails until this holds the digest it pushed
|
|
42
|
+
* (`node docker/harness-images/image.mjs record opencode`).
|
|
43
|
+
*/
|
|
44
|
+
const IMAGE = "ghcr.io/mnaimfaizy/agent-kit-sandbox-opencode";
|
|
45
|
+
const IMAGE_DIGEST = "sha256:6f7c304a8aa75ad823d0f345eeab7024f3bd502ece39211723b05a2ed8699450"; // inputs-bada713720af3f1339b1c796d7efa4ec
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The providers opencode runs on, by its own id for each: the model proxy
|
|
49
|
+
* profile that fronts it, the kit secret that holds its key and the variable
|
|
50
|
+
* that key is read from, the package opencode speaks its API with, and where
|
|
51
|
+
* its API's paths begin on the proxy.
|
|
52
|
+
*/
|
|
53
|
+
export const PROVIDERS = Object.freeze({
|
|
54
|
+
anthropic: Object.freeze({
|
|
55
|
+
displayName: "Anthropic",
|
|
56
|
+
profile: "anthropic",
|
|
57
|
+
secret: "anthropic_api_key",
|
|
58
|
+
env: "ANTHROPIC_API_KEY",
|
|
59
|
+
package: "@opencode/ai/providers/anthropic",
|
|
60
|
+
path: "/v1",
|
|
61
|
+
whereToGet:
|
|
62
|
+
"For an anthropic/ model: create an API key in a dedicated Anthropic Console workspace with its own spend limit: https://console.anthropic.com/settings/keys.",
|
|
63
|
+
}),
|
|
64
|
+
openai: Object.freeze({
|
|
65
|
+
displayName: "OpenAI",
|
|
66
|
+
profile: "openai",
|
|
67
|
+
secret: "openai_api_key",
|
|
68
|
+
env: "OPENAI_API_KEY",
|
|
69
|
+
package: "@opencode/ai/providers/openai",
|
|
70
|
+
path: "/v1",
|
|
71
|
+
whereToGet:
|
|
72
|
+
"For an openai/ model: create an API key in the OpenAI platform, in a project with its own budget: https://platform.openai.com/api-keys.",
|
|
73
|
+
}),
|
|
74
|
+
google: Object.freeze({
|
|
75
|
+
displayName: "Gemini",
|
|
76
|
+
profile: "gemini-api",
|
|
77
|
+
secret: "gemini_api_key",
|
|
78
|
+
env: "GEMINI_API_KEY",
|
|
79
|
+
package: "@opencode/ai/providers/google",
|
|
80
|
+
path: "/v1beta",
|
|
81
|
+
whereToGet:
|
|
82
|
+
"For a google/ model: create an API key in Google AI Studio, in a project with its own budget: https://aistudio.google.com/apikey.",
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/** The model a Stage gets when none is named. */
|
|
87
|
+
export const DEFAULT_MODEL = "anthropic/claude-opus-5-5";
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* What a Consumer needs to know about opencode, which `cli/harnesses.json`
|
|
91
|
+
* publishes per tag (ADR 0030): the kit secrets it accepts, one per provider,
|
|
92
|
+
* with where to get each; no effort values, since opencode has no effort
|
|
93
|
+
* setting (a model's variant, `provider/model#variant`, is part of the model);
|
|
94
|
+
* and the model a Stage gets when none is named.
|
|
95
|
+
*/
|
|
96
|
+
export const FACTS = Object.freeze({
|
|
97
|
+
displayName: "opencode",
|
|
98
|
+
secrets: Object.freeze(
|
|
99
|
+
Object.entries(PROVIDERS).map(([provider, { secret, whereToGet }]) => ({
|
|
100
|
+
name: secret,
|
|
101
|
+
provider,
|
|
102
|
+
whereToGet,
|
|
103
|
+
})),
|
|
104
|
+
),
|
|
105
|
+
effortValues: Object.freeze([]),
|
|
106
|
+
defaultModel: DEFAULT_MODEL,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
/** The tools that reach outside the sandbox, or ask a model API to. */
|
|
110
|
+
export const WEB_TOOLS = Object.freeze([
|
|
111
|
+
"webfetch",
|
|
112
|
+
"websearch",
|
|
113
|
+
"generate_image",
|
|
114
|
+
"generate_video",
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
/** The placeholder the sandbox holds in place of the provider's key. */
|
|
118
|
+
const PLACEHOLDER = "agent-kit-deep-scan-placeholder";
|
|
119
|
+
|
|
120
|
+
/** Every variable a provider's key could sit in, removed from the Launcher's commands. */
|
|
121
|
+
const SCRUB = Object.freeze([
|
|
122
|
+
"ANTHROPIC_API_KEY",
|
|
123
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
124
|
+
"OPENAI_API_KEY",
|
|
125
|
+
"GEMINI_API_KEY",
|
|
126
|
+
"GOOGLE_API_KEY",
|
|
127
|
+
"GOOGLE_GENERATIVE_AI_API_KEY",
|
|
128
|
+
"OPENCODE_API_KEY",
|
|
129
|
+
]);
|
|
130
|
+
|
|
131
|
+
/** The settings every run holds, in the image's system config and the run's own. */
|
|
132
|
+
const PINS = {
|
|
133
|
+
update: "disable",
|
|
134
|
+
share: "disabled",
|
|
135
|
+
websearch: false,
|
|
136
|
+
automations: false,
|
|
137
|
+
policies: WEB_TOOLS.map((tool) => ({
|
|
138
|
+
action: "tool.use",
|
|
139
|
+
resource: `${tool}:*`,
|
|
140
|
+
effect: "deny",
|
|
141
|
+
})),
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const CHOOSE = `name the model provider/model, with a provider that has a model proxy profile: ${Object.keys(PROVIDERS).slice(0, -1).join(", ")} or ${Object.keys(PROVIDERS).at(-1)}`;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The provider and the model's own id that a Stage's model names (none: the
|
|
148
|
+
* default model's), or why it is refused. The refused value is never repeated.
|
|
149
|
+
* @param {string} [model] `provider/model`, with an optional `#variant`
|
|
150
|
+
* @returns {{ provider: string, model: string } | { refused: string }}
|
|
151
|
+
*/
|
|
152
|
+
export function providerOf(model = DEFAULT_MODEL) {
|
|
153
|
+
const named = /^([^/#]+)\/([^#]+)(?:#.*)?$/.exec(model);
|
|
154
|
+
if (named === null) {
|
|
155
|
+
return { refused: `This Stage's model names no provider, which opencode needs: ${CHOOSE}.` };
|
|
156
|
+
}
|
|
157
|
+
const [, provider, id] = named;
|
|
158
|
+
if (!Object.hasOwn(PROVIDERS, provider)) {
|
|
159
|
+
return {
|
|
160
|
+
refused: `This Stage's model names a provider with no model proxy profile, so its key could not stay out of the sandbox: ${CHOOSE}.`,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return { provider, model: id };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The run's config file. Without a proxy address, no base URL. */
|
|
167
|
+
function configJson({ model, provider, id, proxyUrl }) {
|
|
168
|
+
const { env, package: pkg, path } = PROVIDERS[provider];
|
|
169
|
+
return JSON.stringify(
|
|
170
|
+
{
|
|
171
|
+
$schema: "https://opencode.ai/config.json",
|
|
172
|
+
model,
|
|
173
|
+
providers: {
|
|
174
|
+
[provider]: {
|
|
175
|
+
package: pkg,
|
|
176
|
+
settings: {
|
|
177
|
+
...(proxyUrl !== undefined ? { baseURL: `${proxyUrl}${path}` } : {}),
|
|
178
|
+
apiKey: `{env:${env}}`,
|
|
179
|
+
transport: "http",
|
|
180
|
+
},
|
|
181
|
+
// Declared, so a model the bundled catalogue does not know still runs.
|
|
182
|
+
models: { [id]: {} },
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
...PINS,
|
|
186
|
+
policies: [
|
|
187
|
+
{ action: "provider.use", resource: "*", effect: "deny" },
|
|
188
|
+
{ action: "provider.use", resource: provider, effect: "allow" },
|
|
189
|
+
...PINS.policies,
|
|
190
|
+
],
|
|
191
|
+
permissions: [
|
|
192
|
+
{ action: "*", resource: "*", effect: "allow" },
|
|
193
|
+
...WEB_TOOLS.map((action) => ({ action, resource: "*", effect: "deny" })),
|
|
194
|
+
],
|
|
195
|
+
agents: { title: { disabled: true } },
|
|
196
|
+
snapshots: false,
|
|
197
|
+
formatter: false,
|
|
198
|
+
lsp: false,
|
|
199
|
+
},
|
|
200
|
+
null,
|
|
201
|
+
2,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The launch plan for `request`.
|
|
207
|
+
* @param {object} [request] a Stage request, as the Claude Code adapter
|
|
208
|
+
* describes it. `model` is `provider/model` and picks the provider; a
|
|
209
|
+
* provider with no profile throws. `effort` and `maxTurns` are ignored:
|
|
210
|
+
* opencode has no effort setting, and a turn limit it would not report. The
|
|
211
|
+
* only `credentialKind` is `api-key`.
|
|
212
|
+
* @returns the nine-part launch plan, in the same shape as Claude Code's.
|
|
213
|
+
*/
|
|
214
|
+
export function opencode({
|
|
215
|
+
model = DEFAULT_MODEL,
|
|
216
|
+
credentialKind = "api-key",
|
|
217
|
+
proxyUrl,
|
|
218
|
+
briefPath,
|
|
219
|
+
kitDir = "/agent-kit",
|
|
220
|
+
callerKey,
|
|
221
|
+
} = {}) {
|
|
222
|
+
if (credentialKind !== "api-key") {
|
|
223
|
+
throw new Error(`opencode has no credential kind ${JSON.stringify(credentialKind)}`);
|
|
224
|
+
}
|
|
225
|
+
const chosen = providerOf(model);
|
|
226
|
+
if ("refused" in chosen) throw new Error(chosen.refused);
|
|
227
|
+
const { provider, model: id } = chosen;
|
|
228
|
+
const { profile, secret, env } = PROVIDERS[provider];
|
|
229
|
+
const placeholder = callerKey ?? PLACEHOLDER;
|
|
230
|
+
// The config's folder, which the Launcher empties before it writes the file,
|
|
231
|
+
// and the folders opencode writes to while it runs.
|
|
232
|
+
const home = `${kitDir}/opencode`;
|
|
233
|
+
const state = `${kitDir}/opencode-run`;
|
|
234
|
+
const file = `${home}/opencode.json`;
|
|
235
|
+
return {
|
|
236
|
+
identity: { name: "opencode", displayName: "opencode", version: VERSION, major: 2 },
|
|
237
|
+
installLayer: {
|
|
238
|
+
image: `${IMAGE}@${IMAGE_DIGEST}`,
|
|
239
|
+
env: [],
|
|
240
|
+
run: [
|
|
241
|
+
"ln -sf /opt/agent-kit/bin/opencode /usr/local/bin/opencode \\",
|
|
242
|
+
" && mkdir -p /etc/opencode \\",
|
|
243
|
+
` && printf '%s\\n' '${JSON.stringify(PINS)}' > /etc/opencode/opencode.json`,
|
|
244
|
+
],
|
|
245
|
+
},
|
|
246
|
+
modelRoute: { profile },
|
|
247
|
+
credentials: {
|
|
248
|
+
accepted: { "api-key": { secret, env, placeholder } },
|
|
249
|
+
scrub: [...SCRUB],
|
|
250
|
+
},
|
|
251
|
+
launch: {
|
|
252
|
+
argv: [
|
|
253
|
+
"opencode",
|
|
254
|
+
"run",
|
|
255
|
+
// A private server: never the shared one.
|
|
256
|
+
"--standalone",
|
|
257
|
+
// Approves whatever would ask; a denied permission still holds.
|
|
258
|
+
"--auto",
|
|
259
|
+
// Its events go to stdout, the transcript.
|
|
260
|
+
"--format",
|
|
261
|
+
"json",
|
|
262
|
+
],
|
|
263
|
+
// With no message argument, the prompt is read from stdin.
|
|
264
|
+
stdin: briefPath !== undefined ? { file: briefPath } : null,
|
|
265
|
+
files: [{ path: file, text: configJson({ model, provider, id, proxyUrl }) }],
|
|
266
|
+
env: [
|
|
267
|
+
`${env}=${placeholder}`,
|
|
268
|
+
`OPENCODE_CONFIG=${file}`,
|
|
269
|
+
"OPENCODE_DISABLE_AUTOUPDATE=1",
|
|
270
|
+
"OPENCODE_DISABLE_PROJECT_CONFIG=1",
|
|
271
|
+
"OPENCODE_DISABLE_CLAUDE_CODE=1",
|
|
272
|
+
"OPENCODE_DISABLE_MODELS_FETCH=1",
|
|
273
|
+
`XDG_CONFIG_HOME=${home}/xdg-config`,
|
|
274
|
+
`XDG_DATA_HOME=${state}/data`,
|
|
275
|
+
`XDG_STATE_HOME=${state}/state`,
|
|
276
|
+
`XDG_CACHE_HOME=${state}/cache`,
|
|
277
|
+
// opencode takes its base URL from the config; the shell is told the
|
|
278
|
+
// proxy's address too.
|
|
279
|
+
...(proxyUrl !== undefined ? [`AGENT_KIT_MODEL_PROXY_URL=${proxyUrl}`] : []),
|
|
280
|
+
],
|
|
281
|
+
// The Launcher removes `checkoutConfig` from the copy before the launch.
|
|
282
|
+
removeCheckoutConfig: true,
|
|
283
|
+
},
|
|
284
|
+
checkoutConfig: [".opencode", "opencode.json", "opencode.jsonc", ".agents/skills", ".env"],
|
|
285
|
+
instructionFiles: ["AGENTS.md"],
|
|
286
|
+
stops: { turnCap: null },
|
|
287
|
+
transcript: { path: `${kitDir}/logs/agent.log` },
|
|
288
|
+
};
|
|
289
|
+
}
|